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
Hi,
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):

http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html

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

Thanks,
David.

Comments

  • 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)
    end
     
    function IosImagePicker:hasPhotoLibrary()
    	-- Helper method to return true if the device has an active photo library
    	return self:isSourceAvailable(UIImagePickerControllerSourceTypePhotoLibrary)
    end
     
    function IosImagePicker:hasSavedPhotosAlbum()
    	-- Helper method to return true if the device has an active album for saved photos
    	return self:isSourceAvailable(UIImagePickerControllerSourceTypeSavedPhotosAlbum)
    end
    Now you can wrap any call to the image picker with an if test:
        if picker:hasPhotoLibrary() then
    	picker:pickImage(UIImagePickerControllerSourceTypePhotoLibrary,
                    self.onImagePicked, self) 
        end
    best regards
Sign In or Register to comment.