Using NavigationController in an iOS plugin


I’m struggling to build a Unity iOS plugin to display a CNContactViewController as a presentation.

The Obj-c code who seems to pose problem that I’m trying to adapt is :

CNContactViewController *controller = [CNContactViewController viewControllerForUnknownContact:contact];
controller.contactStore = store;
controller.delegate = self;

[self.navigationController pushViewController:controller animated:TRUE];

I understand there is something to do to present the native view over Unity etc. but there is not many documentation or topics about this, I can’t find anything concrete…

Also my knowledge of iOS development / Obj-c are almost null, so it’s hard to understand how everything is related (UiViewController, NavigationController, AppController…)

If someone have some leads where to look at, are explanations about how iOS native and Unity views are related, he’s more than welcome! Thank you very much.


Sorry that this answer is late but here’s what you can use:

Not my project, but you can follow the steps, it’s not too hard there’s only 1 thing a little unclear. ''Make sure AppController extends UnityAppController". So the code he’s showing here isn’t doing this by default. Actually what you have to do is pretty simple, basically you replace “@implementation AppController” with “@implementation AppController: UnityAppController” so it inherits from it.

Other than that you can follow those steps and you’ll have a button made in XCode (with Objective-C) to display over Unity and you can use it.

Side note you can also use Swift with Unity and you can in fact extend UnityAppController in swift also so you could reach the same using Swift. If you’re new to both Swift AND Objective-C, I’d recommend trying Swift instead because while it’s still complex, it’s a lot easier than Objective-C, in my opinion at least. You can follow a few tutorials on Swift that explain optional variables to you and just general stuff about classes etc.

Also if you want to push from Unity to an entirely new UIViewController which contains your layout made in XCode, so basically like an Activity on Android if you’re familiar with this. There’s not much you really have to do, it’s just a bit annoying to find out if you don’t have much knowledge about it.

First of all you can start here: Releases · miyabi/unity-swift · GitHub
this just shows you how to integrate Swift with Unity with a Bridging-Header file ready, you can download the zip for an example project, or simply download the package open it in Unity and you’ll have a Bridging-Header file which you need to use to expose classes to Swift. Now I recommend just building the project first and adding Swift files to your folder in there because it will debug for you instantly rather than doing it inside Unity and having to build then and get errors afterwards. Now what you do in your Swift file is create a class and have it extend UnityAppController, if you can’t find this with Swift, you have to add ‘’#import “UnityAppController.h” to your Bridging-Header, now you can find it. Now type startUnity and it should show up as a function, press enter and it SHOULD compile for you and overrided function. Now inside it call ''super.startUnity(application)" to start Unity up, now if you want to push to another View Controller, what you do is

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as! NextViewController
    UnityGetGLViewController().present(nextViewController, animated:true, completion:nil)

Main should be the name of your storyboard, nextView should be the identifier given to the view you want to show. NextViewController is the class you assigned to nextView.

If you want to first show the Unity view and later call another view with a button for example, you have to create a function.

just create a basic function with the code above in it, however you have to call this function from Objective-C because as far as I know Unity doesn’t allow for you to call Swift directly. To be allowed to call a function from Objective-C you have to put @objc in front of ‘‘func’’ and it must also be a static function. After that just use the same code and in Objective-C call this function and then in Unity call extern void with your Objective-C name.

I’m not sure if you even have to extend UnityAppController at all to do this but it’s what I did so you could try without that part. If it’s not working for you just let me know and I’ll help and try to update this post when I find mistakes because it’s likely I made one, Good luck… If anyone ever reads this :smiley: