简体   繁体   中英

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. Can anybody help me how I can get to know this in iOS?

The getFrom() function in Android has no counterpart for 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.

This is also the suggested workaround mentioned in this answer .

In Appdelegate. Implement below function and you can get it in 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                    
            }

}

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