简体   繁体   English

如何在iOS中从Firebase消息通知中获取主题?

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

In Android you can use getFrom() to read the topic from the notification. 在Android中,您可以使用getFrom()从通知中读取主题。 Can anybody help me how I can get to know this in iOS? 有人可以帮助我如何在iOS中了解这一点吗?

The getFrom() function in Android has no counterpart for iOS. Android中的getFrom()函数没有iOS的对应函数。

As a workaround, you can add in a custom key-value pair for the name of the topic you are sending the message to in your data payload. 解决方法是,您可以在data有效负载中添加自定义键值对,作为将消息发送到的主题的名称。

This is also the suggested workaround mentioned in this answer . 这也是此答案中提到的建议解决方法。

In Appdelegate. 在Appdelegate中。 Implement below function and you can get it in userInfo. 实现以下功能,您可以在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