简体   繁体   中英

Android vs. iOS Notifications w/ Firebase

The issue is, iOS notifications only work properly (when app is active, inactive and terminated) if one sets the notification field (empty or not). However for Android, one is required to not set the notification field and only the data field (otherwise if the app is inactive or terminated the notifications are automatically handled by the system and one can't manipulate them as in download a picture etc.).

How can i display notifications for both in a way that they appear on all states (active, inactive and terminated) and i can manipulate them before the will be displayed?

I manipulate the notifications with these methods:

// Android
onMessageReceived(message: RemoteMessage)

// iOS
didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)

Save and check the device type (android/ios) of the token before sending your request to Firebase from your backend. Compose body of the request accordingly. eg with notification field for the iOS tokens, and with data field for the Android tokens.

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