Callback on launching from URL Scheme?

Is UnityEngine implemented any callback / delegate I can listen to,
for catching app launches with URL scheme?

I can see that the generated Xcode project does something in UnityAppController.mm.

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
    // ...
    AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);
    // ...
}

Which later seems to be sent to a method called onOpenURL:, that I cannot find nor across the project, nor amongst Unity documentation.

Is there some piece of this already implemented in UnityEngine I can use?
I just wanted to be sure about this, don’t want to create another plugin if it is not necessary.


P.S.: The method used above is deprecated.
NS_DEPRECATED_IOS(4_2, 9_0, “Please use application_openURL_options_”)

Woah, there is even a Player Settings… for this.

Mentioned in the Documentation, but could not find further explanation on use iOS Player settings - Unity Manual

Do you mean you want to tell if your app was opened by a url scheme, or detect from your app if other url schemes are called?

Supported URL schemes is so you can call openUrl from your app to that batman app.

Thanks for getting back!
I want the first.

Yap, I just need a callback when my app (batman) was launched via url scheme.
And more important, I need the variables passed into.

All I’m asking if it is implemented in UnityEngine.

1 Like

I don’t believe within Unity, but you could write an iOS plugin that uses iOS methods? See “Handling URL Requests” in that Apple link

Thanks, I know that.
If you take a look at the original question:

Did you find solution for this?

Anyone know how the new Unity inbuilt URL Scheme parameters can be retrieved on launch?

EDIT: Found the answer! NOT SUPPORTED…
https://forum.unity3d.com/threads/5-4b11-ios-url-schemes.393478/#post-2583564

Hey, you can retrieve all the data just fine.

I just shared all my findings / best practices on this topic (and plugin development in general). See tutorial series beginning with…
Override app delegate in Unity for iOS and OSX (1/4)
Plugin workflow
…and more.

2 Likes

Please help upvote issue

https://feedback.unity3d.com/suggestions/receiving-data-when-opened-from-custom-url-scheme

1 Like

In the meantime we have

https://firebase.google.com/docs/dynamic-links/unity/receive

below is a little mm include that passes the whole url to Unity via SendMessage, which works semi-reliably.

#import <UIKit/UIKit.h>
#import "UnityAppController.h"
#import "UI/UnityView.h"
#import "UI/UnityViewControllerBase.h"

@interface strrCusHandler : UnityAppController

void UnitySendMessage( const char * className, const char * methodName, const char * param );

@end

@implementation strrCusHandler

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {

     NSLog(@"url recieved: %@", url);
    
     if (!url) {  return NO; }

    UnitySendMessage("Incoming", "OnOpenWithUrl", [[url absoluteString] UTF8String]);
    return YES;
}   

@end

IMPL_APP_CONTROLLER_SUBCLASS(strrCusHandler)

Similar code in android plugin will work, my problem is I can’t get custom URLs to work reliably in android at all.

2 Likes

hi, polytropoi,
how do i implement your script?

thx.

Does anyone have an update on this? I know the issue is still being voted on in the unity feedback section. My last resort is eppz’s solution, but I’m hoping for a simpler solution. Since my build target is on Mac OS X, I don’t use XCode to build, so I’m not sure how I would go about to implement polytropoi’s solution either.

Edit: I have followed eppz’s override blog post and it took awhile to get setup, but it works, so thanks a lot! Still wish Unity would implement something like this on their side.

Is this still the best solution? I’m surprised there isn’t something in the Asset Store by now, but if there is, I couldn’t find it.

My need is deep linking (i.e. catching the full URL when the app is launched or activated via a URL scheme) on Mac, Windows, and Linux.

EDIT: I think I found just such a plugin; its forum thread is here .

2 Likes

Found this thread on a google search, so thought I’d post that this is implemented in Unity now:

I haven’t tried it on Android yet, but I got it working on iOS.

3 Likes

yep, new deep linking feature works on android fine as well as ios (not sure about windows) - nice to have this integrated at last

1 Like