Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Check sourceType in the IosImagePicker plugin — Gideros Forum

Check sourceType in the IosImagePicker plugin

SimplesAppsSimplesApps Member
edited January 2013 in Plugins
I'm testing the IosImagePicker plugin class from Andy Bower @bowerandy

Before setting the sourceType to the picker (setSourceType(sourceType)) Apple recommends to ask if the sourceType is available by means of calling the isSourceTypeAvailable method of the UIImagePickerController class.
Apple says you never have to assume that a device has a photo library, even if the device has a library, this method could still return NO if the library is currently unavailable, or the device simply has no camera (if you're trying to set it):


How could be improved the code for the IosImagePicker.lua to have this method into account?



  • bowerandybowerandy Guru
    edited January 2013
    @SimplesApps, sorry I didn't see this message when you posted it originally.

    I'm assuming, because you mention IosImagePicker.lua above, that you are using the Hot Wax version of the image picker and not the ObjectiveC plugin that I wrote sometime before. If so, you can easily test a particular source type is available by adding these methods to IosImagePicker:
    function IosImagePicker:isSourceAvailable(sourceType)
    	-- Answer true if the supplied sourceType is actually available on the device
    	return UIImagePickerController:isSourceTypeAvailable(sourceType)
    function IosImagePicker:hasPhotoLibrary()
    	-- Helper method to return true if the device has an active photo library
    	return self:isSourceAvailable(UIImagePickerControllerSourceTypePhotoLibrary)
    function IosImagePicker:hasSavedPhotosAlbum()
    	-- Helper method to return true if the device has an active album for saved photos
    	return self:isSourceAvailable(UIImagePickerControllerSourceTypeSavedPhotosAlbum)
    Now you can wrap any call to the image picker with an if test:
        if picker:hasPhotoLibrary() then
                    self.onImagePicked, self) 
    best regards
Sign In or Register to comment.