Obtaining data sent through custom URL scheme

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?

Warren

@Warren, the easiest way is to make a category on AppController that handles the method.

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.

I need to accomplish the very same thing. Could you provide a little more detail on how you did this?

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

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
	
    if (!url) {  return NO; }
 	
    NSString *URLString = [url absoluteString];
    [[NSUserDefaults standardUserDefaults] setObject:URLString forKey:@"url"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}

Should this work?

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.

I know its been a while, but can you remember what you did exactly?

I’m having the exact same problem and can’t find the offending code (Obj.C newbie).

If i remember correctly, facebookmanager.mm has a handleOpenURL() that you can use

Hi,

I can not get this to work.
I revived an old thread - http://forum.unity3d.com/threads/99323-Start-iOS-App-with-arguments-and-access-them-within-Unity

Any advice is appreciated.