簡體   English   中英

如何在iOS中從Firebase消息通知中獲取主題?

[英]How to get the topic out of a Firebase message notification in iOS?

在Android中,您可以使用getFrom()從通知中讀取主題。 有人可以幫助我如何在iOS中了解這一點嗎?

Android中的getFrom()函數沒有iOS的對應函數。

解決方法是,您可以在data有效負載中添加自定義鍵值對,作為將消息發送到的主題的名稱。

這也是此答案中提到的建議解決方法。

在Appdelegate中。 實現以下功能,您可以在userInfo中獲取它。

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
                     fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
            // Access userInfo
            let aps = userInfo["aps"] as? NSDictionary
            if let aps = aps {
                let alert = aps["alert"] as! NSDictionary
                let body = alert["body"] as! String
                let title = alert["title"] as! String                    
            }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM