Firebase 通知在 iOS 11 中不起作用
Firebase notifications not working in iOS 11
我正在开发一个使用 Firebase 推送通知的应用程序。在我尝试 iOS 11 之前,它运行良好。将 iphone 与 ios 11 一起使用时,通知不会到达。这是我的代码:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)
(UIBackgroundFetchResult))completionHandler {
//Manage notification
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
//Manage notification
}
这两个方法都没有被调用。
感谢您的帮助!
您需要实施 UNUserNotificationCenterDelegate
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert)
}
}
并将其设置为 didFinishLaunchingWithOptions
内的 UNUserNotificationCenter
对象
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
return true
}
在你的项目能力中检查这个。它帮助了我)
这是 Firebase 的问题。这似乎与他们最近的更新有关,而不是 iOS11。他们正在为此进行修复。
同时,如果您将 pod 'FirebaseInstanceID', '2.0.0'
添加到您的播客文件中,它会修复它。
您可以在这里阅读更多内容:https://github.com/firebase/quickstart-ios/issues/327#issuecomment-332655731
你能试试这个吗
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true
我被困了大约 3 个小时,然后在网上找到的 2 个步骤帮助了我。
- 尝试像这样向外部发送调用 firebase 通知 - 只需将 ServerKey 替换为您的帐户服务器密钥,并将 FCM_TOKEN 替换为您的应用程序 fcm 令牌:
curl -X "POST" "https://fcm.googleapis.com/fcm/send" \
-H "Authorization: key=ServerKey" \
-H "Content-Type: application/json" \
-d $'{
"notification": {
"body": "Testing with direct FCM API",
"title": "Test Message",
"badge": "0",
"sound": "default"
},
"registration_ids": [
"FCM_TOKEN"
]
}'
- 您可能会收到一些错误响应。我有 "InvalidApnsCredential" 这是由于 firebase 和 apple 开发者帐户中的 TeamID 不匹配(更具体地说是身份验证令牌密钥)-> 还要注意 firebase 在保存后确实更改了 TeamID 事件(它给了我很多无效的保存更改浏览器刷新后发生)
我也遇到了这个问题。我已按照所有说明进行操作,但仍然无法在后台收到通知。
当我存档并将构建发送到试飞(并得到苹果批准)时,问题就消失了。不,我可以发送通知。
我正在开发一个使用 Firebase 推送通知的应用程序。在我尝试 iOS 11 之前,它运行良好。将 iphone 与 ios 11 一起使用时,通知不会到达。这是我的代码:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)
(UIBackgroundFetchResult))completionHandler {
//Manage notification
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
//Manage notification
}
这两个方法都没有被调用。
感谢您的帮助!
您需要实施 UNUserNotificationCenterDelegate
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert)
}
}
并将其设置为 didFinishLaunchingWithOptions
UNUserNotificationCenter
对象
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().delegate = self
return true
}
在你的项目能力中检查这个。它帮助了我)
这是 Firebase 的问题。这似乎与他们最近的更新有关,而不是 iOS11。他们正在为此进行修复。
同时,如果您将 pod 'FirebaseInstanceID', '2.0.0'
添加到您的播客文件中,它会修复它。
您可以在这里阅读更多内容:https://github.com/firebase/quickstart-ios/issues/327#issuecomment-332655731
你能试试这个吗
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true
我被困了大约 3 个小时,然后在网上找到的 2 个步骤帮助了我。
- 尝试像这样向外部发送调用 firebase 通知 - 只需将 ServerKey 替换为您的帐户服务器密钥,并将 FCM_TOKEN 替换为您的应用程序 fcm 令牌:
curl -X "POST" "https://fcm.googleapis.com/fcm/send" \ -H "Authorization: key=ServerKey" \ -H "Content-Type: application/json" \ -d $'{ "notification": { "body": "Testing with direct FCM API", "title": "Test Message", "badge": "0", "sound": "default" }, "registration_ids": [ "FCM_TOKEN" ] }'
- 您可能会收到一些错误响应。我有 "InvalidApnsCredential" 这是由于 firebase 和 apple 开发者帐户中的 TeamID 不匹配(更具体地说是身份验证令牌密钥)-> 还要注意 firebase 在保存后确实更改了 TeamID 事件(它给了我很多无效的保存更改浏览器刷新后发生)
我也遇到了这个问题。我已按照所有说明进行操作,但仍然无法在后台收到通知。
当我存档并将构建发送到试飞(并得到苹果批准)时,问题就消失了。不,我可以发送通知。