How does one get access to existing photos on an iDevice?
My app allows users to take a photo and load it into an image viewer. If one tries to take a new photo, and the image viewer has an image, it seems to bring up a photo picker. However, if no image is already in the image viewer it brings up the camera. How do I tell it to bring up an image picker no matter the state of the image viewer?
Cheers.
It depends what class you are using to access photos. If you are using the UIImagePickerController then you just have to change the source type. If you are using something else you will have to tell us what it is to advise you. UIImagePickerController Is readily and freely available in iOSKit if you have not yet stumbled upon my library.
Hi Jason,
I have stumbled on your iOSKit, and it is brilliant!
I used your camera example to incorporate the ability to take photos, to my app.
Is there a sample, in your kit, to show the use of the UIImagePickerController? If there is, I have missed it… which is entirely possible.
Hi Jean-Paul. Looking into that now, cheers.
You need to set the source type depending on what you want. If you are using the “Camera” class from the extensions module I no longer recommend this because Apple doesn’t like reusing the UIImagePickerController object like that class does. Instead you should just create a UIImagePickerController directly as necessary and set the source type as required. Hopefully that makes sense?
Just by way of an example, I tried this:
Dim tmpPicker as UIKit.UIImagePickerController
tmpPicker = new UIKit.UIImagePickerController
tmpPicker.sourceType = UIImagePickerController.sourceType.PhotoLibrary
tmpPicker.TakePicture
ImageView1.Image = tmpPicker.originalImage
But get an error of “This item does not exist” in connection with the “tmpPicker.sourceType = UIImagePickerController.sourceType.PhotoLibrary” statement, highlighting the “UIImagePickerController.sourceType” bit.
Am I just too dumb for words, or should this not work? haha
Cheers.
IMHO dtPlugins is far simpler to use.
Hi Michel,
On the surface it does, yes, but the sample application included in the download doesn’t work. I get a black screen, then it seems to crash.
Have you tried it? I would be interested to hear if it is something to do with my environment, or globally.
Cheers.
Bobby
You need to include the full module prefix so UIKit.UIImagePickerController.sourcetypes.photolibrary. This is caused by Xojo, not me. I’ve personally never been able to get the dtPlugins examples to work, but some people here use them to great success.
HI Jason,
I tried that, after that post, and the same.
Dim tmpPicker as UIKit.UIImagePickerController
tmpPicker = new UIKit.UIImagePickerController
tmpPicker.sourceType = UIKit.UIImagePickerController.sourceType.PhotoLibrary
tmpPicker.TakePicture
ImageView1.Image = tmpPicker.originalImage
ImageView1.Invalidate
.b
[quote=272992:@Robert Holder]Hi Michel,
On the surface it does, yes, but the sample application included in the download doesn’t work. I get a black screen, then it seems to crash.
Have you tried it? [/quote]
Yes, I tried, and it worked flawlessly. But something may have changed with iOS 9.32
Same behaviour on my iPhone (v8.4.1) and my iPad (v9.3.2).
It almost seems the issue is that the “Allow access to photos” isn’t coming to the front, as if you terminate the app you see that message briefly.
Those are only devices on which I can test, at this stage.
Sorry I just looked back over the code, the enumeration is called Source so you should set the type as UIKit.UIImagePickerController.Source.PhotoLibrary. SourceType is the property, Source is the type of that property.
Hi Jason,
Still no go for me.
Maybe my thinking is just too obtuse. The sample project is here: http://cloud.techternatives.com/index.php/s/ppj7Q9MhydwlIs4
I would appreciate you trying to compile and to see what I am missing.
Cheers.
.b
I won’t be able to take a look at this until tomorrow (I’m on my phone now) but I will let you know what I find when I do.
Thanks mate, much appreciated.
So the task I thought I had for today cleared up and I took a look. Here is a now working project:
https://www.dropbox.com/s/6efdp83r80ccgzh/imagepicker.xojo_binary_project?dl=0
The main issue you had is that the UIImagePickerController is asynchronous in nature and you get a notification in the form of an event when it has been successfully taken. Also the TakePicture method only works when you are in camera mode, if you are choosing from the camera roll you just have to present the picker with the PresentInView method. Either way (if you are using the camera or the saved photos library) you must still present the view to actually do anything and then wait for the notification to proceed with the supplied image. The TakePicture method looks nice but is actually only intended for use if you are using a custom view and not the default button supplied by Apple to take a picture which is much more complicated to set up.
Jason
Thanks heaps, Jason!
My app uses your camera class form the example for taking photos, would you recommend I use this method, instead? In a previous post you said you no longer recommend the exampled class approach.
Cheers.
Bobby
Indeed, I would use the approach I outlined in your updated example and not use the Camera class.
Done. Thanks again for your assistance.