问题描述
我的应用程序具有带有消息有效负载设置的FCM,并且在Xcode调试模式下运行以及测试人员从TestFlight下载发行版时,可以使用APNs Auth Key成功运行。在Firebase项目设置中也正确设置了App Store ID和Team ID。
但是我发现,如果我首先从AppStore安装应用程序(该构建具有相应的GoogleService-Info.plist,但尚未实现完整的FCM功能),然后通过TestFlight构建覆盖该构建(此构建已完成FCM功能),该应用仍可以获取FCM令牌,但似乎没有收到任何FCM消息。如果我使用Firebase的Notification composer发送带有接收到的令牌的消息,则该应用实际上可以接收到该通知,因此这意味着应正确设置APN。
我搜索了类似的问题,发现this question似乎和我的问题相似,但还是有些不同。但是没有答案,所以我仍然不知道。
我的问题是,当直接从TestFlight下载(工作正常)以及从AppStore的“重写”功能时,可能导致应用程序上的FCM工作不同的原因是什么?同样,我最大的担忧是,当最终将应用程序从AppStore旧版本更新为新版本时,FCM是否能正常工作?
与AppDelegate中的接收消息/通知有关的某些代码设置。我省略了代理设置代码。
//Handle messages with method swizzling disabled
@available(iOS 10,*)
extension AppDelegate : UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter,willPresent notification: UNNotification,withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
os_log("didReceiveRemoteNotification: %{public}@",log: LogCategories.FCMSetup,type: .debug,userInfo)
AppDelegate.getFcmClient().processMessaging(center,willPresent: notification,withCompletionHandler: completionHandler)
// With swizzling disabled you must let Messaging know about the message,for Analytics
Messaging.messaging().appDidReceiveMessage(userInfo)
}
// This is received when app is backgrounded and then reopen
func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let messageID = userInfo[FCMClient.gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
os_log("didReceiveUserNotification: %{public}@",userInfo)
completionHandler()
}
}
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging,didReceiveRegistrationToken fcmToken: String) {
// Note: This callback is fired at each app startup and whenever a new token is generated.
AppDelegate.getFcmClient().setNewToken(fcmToken)
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"),object: nil,userInfo: dataDict)
os_log("Firebase registration token received: %{public}@",fcmToken)
}
func messaging(_ messaging: Messaging,didReceive remoteMessage: MessagingRemoteMessage) {
AppDelegate.getFcmClient().processMessaging(messaging,didReceive: remoteMessage)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)