简体   繁体   中英

Deep link in FCM notification iOS

I have an app made with Unity and would like to add deep links using FCM. Everything works fine on Android, but I can't get it working on iOS.

Following this manual and this answer .

Issue is that Application.absoluteURL is empty in Unity on iOS when app opens from notification . If I click same link on a webpage or in messenger everything works as expected. So I suppose that problem is in the way my notification is composed.

I think that I need use some other key (not link for iOS), but I'm not sure (tried deepLink , deeplink , url , link and some others, but no luck yet). This is what works for me on Android.

{
 "to" : "{token}",
 "notification" : {
     "body" : "Body",
     "title": "Title",
     "link": "mylink://sometext"
 }
}

Any suggestions appreciated.

Ok, got this working. Instead of relying on Application.absoluteURL I used Firebase.Messaging.FirebaseMessaging.MessageReceived that fires when message from FCM is received (yes, this approach works even if the app was not running).

So basically just handle notification payload inside of the app. Here is the method that is subscribed to above event:

 public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
    {
        UnityEngine.Debug.Log("Received a new message data: " + e.Message.Data);
        foreach(KeyValuePair<String, String> pair in e.Message.Data)
        {
            if(pair.Key == [YOUR_MAP_KEY_HERE] && pair.Value.Contains([YOUR_MAP_VAL_HERE]))
            {
                //do some action
            }
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM