Accessing iOS SDK possible?

Is there any documentation or information on how I should go about accessing iOS SDK for iOS specific code?

Hi ,

You can do iOS specific stuff like you would in a non-UE project. All .cpp files are compiled in mixed mode, so you can include objective C along side your C++. For some examples, check out Engine\Source\Runtime\Core\Private\IOS\IOSAppDelegate.cpp and Core.Build.cs.

For example, IOSShowLeaderboardUI calls ShowLeaderboard which shows the OS-specific leaderboard display (GKGameCenterViewController), imported in the header via import <GameKit/GKGameCenterViewController.h> and reported as a required framework in Core.Build.cs via PublicFrameworks.AddRange.

Note: The most important gotcha is that the Unreal game thread is not the iOS main thread. This means you usually need to use performSelectorOnMainThread to get from the UE main thread to the iOS main thread, and FIOSAsyncTask CreateTaskWithBlock to get back from the iOS thread to the game thread.

Cheers,

1 Like

Hi,

thanks Michael for the exmaple.

I want to show the iOS Photo Gallery so that a user can pick a photo. Unfortunately I am very new to Objective-C and also don’t know how I can get it to work with the Engine.

  1. I created a header .h and .cpp file, for my ObjC code. I can only compile this code if I put preprocessor tags (#if PLATFORM_IOS … #endif) around the whole code. I guess that at this point I am already doing something wrong, as I thought the preprocessor tags should not be necessary, because of the mixed mode you were talking about?!
  2. I tried to include the

IOSAppDelegate.h

to use functions like


ShowController

file but I get the error that the file could not be found. Also I do have to include the


myproject.h

file.

My AppViewController.h looks like:



#pragma once

#if PLATFORM_IOS

#import <UIKit/UIKit.h>

// UIImagePickerControllerDelegate to respond to user interactions
// UINavigationControllerDelegate because we want to present the photo library modally
@interface APPViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

// select a photo from the photo library
+ (void) selectPhoto;

@end
#endif


My AppViewController.cpp file:



#include "myproject.h"

#if PLATFORM_IOS
    #include "IOSAppDelegate.h"
#endif

#include "APPViewController.h"

#if PLATFORM_IOS

@interface APPViewController ()
@end

@implementation APPViewController

- (void) selectPhoto {
    // TODO switch to iOS main thread and back again?

    // 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
    [self ShowController : picker];
}

@end
#endif


How would I call my


selectPhoto

function from another C++ class. Simply using


[AppViewController selectPhoto];

?

I have the very strong feeling that I’m doing this terribly wrong. Would really appreciate some assistance. Thanks.

For everyone interested, this is my working code How to access iOS photo library / use Objective-C properly? - Plugins - Epic Developer Community Forums

Great work! This is really useful, it should be put on the wiki.

Hi. I was trying to use your solution. I made a blueprint callable function that calls your runSelectPhoto. I think the call works, as the dialog asking for permission to open album appears, but the game crashes after I gave permission. I don’t know if something has changed, I am testing on iOS9.
What I am trying to do is to take a screenshot with UIImageWriteToSavedPhotosAlbum, but I don’t know Objective-C, so I was trying your code to learn a little.

I would appreciate anyone help.

Sorry newb here, but was reading the thread, is there any swift support for this? Because I just learned Swift…anyhow if not, what’s the best resource to get started with the SDK? Thanks in advance!

I also tried the solution, and was getting the same issue on iOS10. Turns out, the app has to be run in portrait orientation for the picker to not crash. See my info on this thread: how-to-access-ios-photo-library

What header should we include in order to use FIOSAsyncTask? - In my case, I have build error: “use of undeclared identifier ‘FIOSAsyncTask’”

Thanks a Lot :clinking_glasses: