简体   繁体   English

FCM 通知中的深层链接 iOS

[英]Deep link in FCM notification iOS

I have an app made with Unity and would like to add deep links using FCM.我有一个用 Unity 制作的应用程序,想使用 FCM 添加深层链接。 Everything works fine on Android, but I can't get it working on iOS.在 Android 上一切正常,但我无法在 iOS 上正常工作。

Following this manual and this answer .遵循本手册此答案

Issue is that Application.absoluteURL is empty in Unity on iOS when app opens from notification .问题是当应用程序从通知打开时,iOS 上的 Unity 中的Application.absoluteURL为空。 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).我认为我需要使用其他一些密钥(不是 iOS 的link ),但我不确定(尝试deepLinkdeeplinkurllink和其他一些,但还没有运气)。 This is what works for me on Android.这在 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).我没有依赖Application.absoluteURL ,而是使用Firebase.Messaging.FirebaseMessaging.MessageReceived ,它在收到来自 FCM 的消息时触发(是的,即使应用程序没有运行,这种方法也有效)。

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
            }
        }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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