I am a facing a strange issue in ios firebase push notification. I am getting a notification on device whenever I run the app from Xcode or even when I create an archive I am successfully getting notifications.
But when I run a release build on device or upload to app store push notifications are not working for me and I am getting the error below
Certificates for both development and production are uploaded and are valid.
{
"multicast_id": 6319718121948146737,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
second time when I call API with same token then instead of InvalidRegistration
I get NotRegistered
error
This is how I am generating fcm token
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Pass device token to auth
#if DEVELOPMENT
Auth.auth().setAPNSToken(deviceToken, type: .sandbox)
Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
#else
Auth.auth().setAPNSToken(deviceToken, type: .prod)
Messaging.messaging().setAPNSToken(deviceToken, type: .prod)
#endif
Messaging.messaging().apnsToken = deviceToken
Messaging.messaging().shouldEstablishDirectChannel = true
//tried this
let token = Messaging.messaging().fcmToken
print("Firebase registration token: \(token)")
//tried this also both are giving same token but none of them is
//working in release build
let refreshedToken = InstanceID.instanceID().token()
print("InstanceID token: \(refreshedToken)")
}
Finally, I solved this issue by removing this part from my code
#if DEVELOPMENT
Auth.auth().setAPNSToken(deviceToken, type: .sandbox
Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
#else
Auth.auth().setAPNSToken(deviceToken, type: .prod)
Messaging.messaging().setAPNSToken(deviceToken, type: .prod)
#endif
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.