ios - Firebase Notification To Device with FCM Token Says Sent but not received -
i attempting send simple push notification firebase notification console specific device using fcm token. firebase notification console shows notification sent device not receive it. have tried sending notification , waiting see if console logs didreceiveremotenotification
, notification takes long (hours) shown sent in firebase console (even when set priority high
).
app delegate
import uikit import firebase import firebasestorage import firebasedatabase import firebasemessaging import coredata import usernotifications @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate, unusernotificationcenterdelegate { var window: uiwindow? func application(_ application: uiapplication, didfinishlaunchingwithoptions launchoptions: [uiapplicationlaunchoptionskey: any]?) -> bool { // override point customization after application launch. // use firebase library configure apis firebaseapp.configure() ///// // firebase cloud messaging (fcm) if #available(ios 10.0, *) { // ios 10 display notification (sent via apns) unusernotificationcenter.current().delegate = self let authoptions: unauthorizationoptions = [.alert, .badge, .sound] unusernotificationcenter.current().requestauthorization( options: authoptions, completionhandler: {_, _ in }) } else { let settings: uiusernotificationsettings = uiusernotificationsettings(types: [.alert, .badge, .sound], categories: nil) application.registerusernotificationsettings(settings) } application.registerforremotenotifications() // end of [for firebase cloud messaging (fcm)] ///// return true } /////////////////////// // fcm setup // monitor token generation fcm: notified whenever fcm token updated func messaging(_ messaging: messaging, didrefreshregistrationtoken fcmtoken: string) { print("firebase registration token: \(fcmtoken)") } // monitor token generation fcm: func application(_ application: uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken: data) { messaging.messaging().apnstoken = devicetoken } // handle messages received through fcm apns interface func application(_ application: uiapplication, didreceiveremotenotification userinfo: [anyhashable: any]) { print("didreceiveremotenotification") // if receiving notification message while app in background, // callback not fired till user taps on notification launching application. // todo: handle data of notification // swizzling disabled must let messaging know message, analytics // messaging.messaging().appdidreceivemessage(userinfo) // print message id. // gcm_message_id if let messageid = userinfo["gcmmessageidkey"] { print("message id: \(messageid)") }
^my guess issue may have "gcm_message_id"/"gcmmessageid"/"gcm.message_id" different in each of 3 approaches tried below
// print full message. print(userinfo) } // handle messages received through fcm apns interface func application(_ application: uiapplication, didreceiveremotenotification userinfo: [anyhashable: any], fetchcompletionhandler completionhandler: @escaping (uibackgroundfetchresult) -> void) { print("didreceiveremotenotification (withcompletionhandeler)") // if receiving notification message while app in background, // callback not fired till user taps on notification launching application. // todo: handle data of notification // swizzling disabled must let messaging know message, analytics // messaging.messaging().appdidreceivemessage(userinfo) // print message id. if let messageid = userinfo["gcmmessageidkey"] { print("message id: \(messageid)") }
^my guess issue may have "gcm_message_id"/"gcmmessageid"/"gcm.message_id" different in each of 3 approaches tried below
// print full message. print(userinfo) completionhandler(uibackgroundfetchresult.newdata) } // end of [fcm setup] /////////////////////// }
view controller
class viewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // retrieve current registration token firebase cloud messaging (fcm) let token = messaging.messaging().fcmtoken print("fcm token: \(token ?? "")") } }
entitlements & enabling push notifications
i have added push entitlements , enabled background modes push notifications , added googleservice-info.plist project.
method sending notification
i creating notification firebase notifications console (as shown below) there should no issue structure of notification itself.
i have tried following approaches remedy issue, have produced same result:
does know why notification being marked sent in firebase notification console not showing on device?
a couple of troubleshooting steps use when working push notifications are:
- get push working independent of firebase services first. use tool.
- make sure dont have bundle identifier namespace collisions. example having combination of appstore build, testflight build, , / or develop build of app on device. delete 1 instance of app. bundle identifier how device knows app route push notification to.
- when else fails - try isolate issue building new sample project , hook new firebase project , see if can narrow focus down being able push working without other business logic in app. helps me prove self haven't gone insane, , proves me it's not mysterious network condition leading woes.
i hope helps you work figured out.
Comments
Post a Comment