Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to access iOS photo library / use Objective-C properly?

Hi there,

using UE 4.6.1 on Windows, I have a code project and am packaging it for iOS.

I was wondering whether it is possible to access / communicate with the iOS Photo library / app or with the camera, as I want the user to pick a picture in game. Unfortunately I didn't find anything about that.

Would I have to write an iOS plugin or could I use a library or framework which does that? Do I have to develop on a Mac, using XCode to be able to do that?

Is there any information about it?

Product Version: Not Selected
more ▼

asked Jan 27 '15 at 12:03 PM in C++ Programming

avatar image

551 29 33 181

avatar image trutty Feb 16 '15 at 10:35 AM

So, I can use Objective-C code when wrapped around with the preprocessor tag

     // objc code

What I need to have is something like this camera app, where, after the click of a UMG button, the Photo Library would pop up so that a user can pick a photo. Seems like I need a ViewController for this but I don't know how to properly implement it so that my button click executes the ObjC code and stuff.

Some hints or even a general direction would be really nice.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first

I figured out how to achieve this. For everyone interested, here is the code:


 #pragma once
 #import <UIKit/UIKit.h>
 // UIImagePickerControllerDelegate to respond to user interactions
 // UINavigationControllerDelegate because we want to present the photo library modally
 @interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
 // function to run in iOS main thread
 + (void) runSelectPhoto;


 // ...
 #include "IOSAppDelegate.h"
 #import <Foundation/Foundation.h>
 #include "MyViewController.h"
 @interface MyViewController()
 @implementation MyViewController
 + (MyViewController*)GetDelegate
     static MyViewController * Singleton = [[MyViewController alloc] init];
     return Singleton;
     // create the Photo Library display object
     UIImagePickerController *picker = [[UIImagePickerController alloc] init];
     // type of picker interface to be displayed by the controller
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
     // delegate object which receives notification when the user picks an image or exits the picker interface
     picker.delegate = self;
     // show object
     // the UIImagePickerController is ONLY supported in portrait mode (see http://stackoverflow.com/a/16346664/4228316)
     [[IOSAppDelegate GetDelegate].IOSController presentViewController : picker animated : NO completion : nil];
     // perform this action on the iOS main thread
     [[MyViewController GetDelegate] performSelectorOnMainThread:@selector(selectPhoto) withObject:nil waitUntilDone : NO];
 #pragma mark - Image Picker Controller delegate methods
 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo : (NSDictionary *)info{
     // get the chosen original image
     UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
     // ...
     // call C++ functions on the game thread
     [FIOSAsyncTask CreateTaskWithBlock : ^ bool(void)
         // call C++ functions
         // ...
         return true;
     // get rid of UIImagePicker
     [picker dismissViewControllerAnimated : YES completion : NULL];
 -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
     [picker dismissViewControllerAnimated : YES completion : NULL];

The method to show the image picker is called with

     NSLog(@"Show image picker");
     [MyViewController runSelectPhoto];
more ▼

answered Feb 19 '15 at 10:41 AM

avatar image

551 29 33 181

avatar image romfeo Aug 20 '15 at 06:42 PM

Sorry to bump this up? Can I use this methodology only in the source code version of UE4, or in the Launcher version as well? Can I then expose some function in blueprints?

avatar image Shadowriver Sep 24 '15 at 08:47 PM

It should work i think, you need source code to modify engine or build it in custom configuration that laucher does not provide

avatar image ArkanSephin Sep 24 '15 at 01:59 PM

u have a sample for android devices?

avatar image theonecalledtom Jun 27 '16 at 06:33 PM

I was wondering if this conversation is still the state of the art? Seems like a nice feature to wrap up cross platform and add to the engine.

avatar image theonecalledtom Jul 01 '16 at 02:29 PM

Another question - are your files above in your project or at the engine level? I have a couple of small iOS features to implement in objective C but would like to stay clear of engine modifications as far as possible.

Thanks for posting the code btw - VERY helpful :)

avatar image theonecalledtom Jul 02 '16 at 05:37 AM

Well blow me down I just slapped it in cpp / h files in my project and it just worked (tm).

Thanks again!

avatar image ansonkit Sep 05 '16 at 06:39 AM

hi guys~i no a programmer ,can you guys teach me you to activate it? can show some step~thank you

avatar image jdannenbring Feb 21 '17 at 02:34 AM

I used this code in 4.15 and was able to build and deploy to my iOS 10 device. However, whenever the "runSelectPhoto" method is executed the app crashes.

I've got the proper permissions in the pList file (NSPhotoLibraryUsageDescription) and the app requests permission correctly (which I allow).

EDIT: The crash is caused because the photo library requires the app be in portrait mode. If you change your app to run in portrait mode (Project Settings->iOS->Orientation) You have to select Support Portrait Orientation and deselect Landscape Left/Right.

avatar image Bamwd5 Feb 22 '17 at 07:47 PM

Hey guys:

Very helpful. Thanks for the info and the check in 4.15!

If you think this would work in the launcher version of UE4, can you describe steps of how to integrate the cpp and .h file into a new project? For instance, where to store these files and how to access them from the editor?


avatar image MJZALDIVAR Nov 04 '17 at 07:49 PM

Hi, It's my first project working for iOS with UE4(4.17.2) - I see your code and dude, thank you for the clear explanation. However there is a detail is not that clear to me: Can I just write this code block inside a C++ function? #if PLATFORM_IOS NSLog(@"Show image picker"); [MyViewController runSelectPhoto]; #endif So far, I compiled the class and it was successful, but I was wondering about how to call the functions wrote with ObjectiveC

avatar image Hammadfozi.BIM Feb 26 '19 at 12:23 PM

Hi. I'm un-sure how to use the resultant UIImage object. The end-result I'm looking for is to have a UE4 Texture that I can assign to an image.

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; Want to be able to convert this to a UE4 Texture.

Any help on this is appreciated. Thanks.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question