It is common to register a custom url for an iOS app and then launch the app using that url scheme. For example:
myapp://?data1=blue&data2=green
would launch the app bound to “myapp” and provide the data string “?data1=blue&data2=green” when the app is launched.
What is the best way to obtain that data string in Unity? Is there built in functionality for something like this? I see that AppController and iPhone_target2AppDelegate in the iPhone project both implement AppDelegate, but neither implements handleOpenURL.
Is it best to override these as a post process in my build? Has anyone else come up with a good way to handle this?
Thanks, Prime31. I’m using a post build process script to add a method to the AppController and that seems to be working. I think I can store the data in global variables and then read them back out through a plugin.
edit: the bellow code indeed works, as long as you don’t have another plugin conflicting with it (for me, it was social networking plugin). then just check “url” in playerprefs.
////////////////////
I’d love a working example, too. I thought I’d gotten it working a couple weeks ago, but now I can’t get it to do anything when it launches via url
In AppController.mm after didFinishLaunchingWithOptions’s stuff I put this in
Well, it appears that my code SHOULD work. Got it working easily in a fresh project, but something must be conflicting now.
edit: I can stop pulling my hair out now – found that social network plugin was nullifying my code. found where it handles it in FacebookManager.mm and added what I needed there.