- Home /
Accessing the iOS Photo Picker?
Is there a way to access the iOS Photo Picker from Unity? I want my Unity application to let the user select a picture from the Photos application or take another picture using the camera, if the device has it. I was unable to find anything about it on the documentation.
Thanks in advance.
Answer by Peter G · Dec 27, 2010 at 04:04 PM
You have to use a plugin through obj-c. It's not that hard.
Hide or remove the Unity view.
Add a view controller with a view to the keyWindow
.
Create a button or some event that opens an UIImagePickerController
which you shouldn't need to subclass.
Have your viewController respond to the image picker delegate.
Once the user chooses an image save the image See SpinalJack's Post on getting the asset path. See below for code.
In Unity, use a WWW
to load the image from the asset path.
When loading your data, the only thing you will need to remember is that WWW wants file:
at the beginning and your plugin will not so add that after you send the asset path to your native code.
(void)imagePickerController:(UIImagePickerController )picker didFinishPickingImage:(UIImage )selectedImage editingInfo:(NSDictionary *)editingInfo {
NSData* imageData = UIImagePNGRepresentation(selectedImage);
[imageData writeToFile:assetPath atomically:YES];
[self dismissModalViewControllerAnimated:YES];
}
Looks nice, indeed. But how do I add Obj-C plugins to Unity? Thanks!
http://unity3d.com/support/documentation/$$anonymous$$anual/Plugins.html#iPhonePlugins and look at the Bonjour example. It makes more sense when you see it.
why do we need to hide or remove the unity view? is it incorrect to present the image picker directly from the keywindow unityViewController?
Answer by xpkoalz · Dec 10, 2014 at 10:06 AM
How do I hide Unity View? I can't find a simple or straight-forward answer to this..
Your answer
Follow this Question
Related Questions
Access to iPad2/iOS camera as texture 4 Answers
Unity Freezes and Deletes Everything in My Scene 0 Answers
Make custom input devices available to scripting via "Input" 2 Answers
Controller Not Recognized on One Computer 0 Answers
Porting Unity Web Player game to iPhone using Unity 1.7 iPhone 1 Answer