重新安装应用程序后,iOS推送通知不再起作用

时间:2020-09-29 12:14:45

标签: ios firebase curl push-notification firebase-cloud-messaging

首先,我用于创建iOS的Google Firebase FCM连接(https://firebase.google.com/docs/ios/setup#objective-c_1)的相关代码段:

[FIRApp configure];

[...]

[[FIRInstanceID instanceID] instanceIDWithHandler:^(FIRInstanceIDResult * _Nullable result,
                                                    NSError * _Nullable error) {
    if (error != nil) {
        // "Error fetching remote instance ID:" << error;
    } else {
        if(result != nil) {
            //result.token;
        }
    }
}];

以下代码注册“ didReceiveRemoteNotification”并处理推送通知: (https://firebase.google.com/docs/cloud-messaging/ios/client#objective-c_2https://firebase.google.com/docs/cloud-messaging/ios/receive):

if ([UNUserNotificationCenter class] != nil) {
  // iOS 10 or later
  // For iOS 10 display notification (sent via APNS)
  [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
      UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  [[UNUserNotificationCenter currentNotificationCenter]
      requestAuthorizationWithOptions:authOptions
      completionHandler:^(BOOL granted, NSError * _Nullable error) {
        // ...
      }];
} else {
  // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
  UIUserNotificationType allNotificationTypes =
  (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
  UIUserNotificationSettings *settings =
  [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
  [application registerUserNotificationSettings:settings];
}

[application registerForRemoteNotifications];

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[...]
}

当我执行如下操作时,所有这些代码都运行良好:

curl -H "Content-Type: application/json" -H "Authorization:key=XXXXXXXXXXXXXXX" -X POST -d '{"notification":{"title":"POST Message","body":"This is a test message"},"to":"ekQdJU_1nf4:APA91bFSw7UaXXXXXXXXVUWxKSv34-fAcgzO63INreZXXXXXq_v8nWZSOafg_ghXXXXXXXXXXXyLSA4MbHfUzRjX9q4OSjXXXXX8EXdrYr8z9glVnR417Y"}' https://fcm.googleapis.com/fcm/send
{"multicast_id":6222431986216858457,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"1601373230081911"}]}

现在,我更新了我的应用程序,完成了一些工作,还添加了Google Analytics(分析)等。 更新我的应用程序后,推送通知仍然可以毫无问题地发送。

问题

重新安装应用程序并重新创建Firebase令牌后,推送通知停止工作:

curl -H "Content-Type: application/json" -H "Authorization:key=XXXXXXXXXXXX" -X POST -d '{"notification":{"title":"POST Message","body":"This is a test message"},"to":"dFYiAXXXXXX61IaJ8Lq:APA91bELTXXXXXXXXXXN1nUdqhMBGWY7bkRl1At3XDcBCfIp4q2zHDlX5gtwi65yFJpoj5RqlLFOD34O1qK4c01hgzp1UeyZXXXXXXXHRkMVf"}' https://fcm.googleapis.com/fcm/send{"multicast_id":8667655177256903166,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1601373391615905%c2da97ddc2da97dd"}]}

回调didReceiveRemoteNotification不再被调用。

问题

有人提示我的应用程序必须进行哪些更改,以使Push通知停止工作? 如果更新没有成功并且没有重新安装,则说明Firebase令牌创建一定有问题。但是创建令牌的代码并未更改。

唯一的更改是添加了Google Analytics(分析)内容。

有人可以解释curl message_id响应的含义吗?

0:1601373391615905%c2da97ddc2da97dd

0 个答案:

没有答案