【发布时间】:2017-01-28 18:44:29
【问题描述】:
我正在使用 FCM(Firebase 云消息传递)在 iOS 中发送推送通知。
当应用程序处于前台状态时,我能够收到通知。但是当应用程序处于后台状态时,没有收到通知。每当应用程序进入前台状态时,才会收到通知。
我的代码是:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
// Print message ID.
NSDictionary *userInfo = notification.request.content.userInfo;
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);
// Pring full message.
NSLog(@"%@", userInfo);
if( [UIApplication sharedApplication].applicationState == UIApplicationStateInactive )
{
NSLog( @"INACTIVE" );
completionHandler(UNNotificationPresentationOptionAlert);
}
else if( [UIApplication sharedApplication].applicationState == UIApplicationStateBackground )
{
NSLog( @"BACKGROUND" );
completionHandler( UNNotificationPresentationOptionAlert );
}
else
{
NSLog( @"FOREGROUND" );
completionHandler( UNNotificationPresentationOptionAlert );
}}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
App处于后台状态时:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
-- 根本没有被调用。
我在 App Capabilities 的后台模式中启用了推送通知和远程通知。但是App仍然没有收到通知。
我提到了一些 StackOverflow 问题,但无法解决问题。 iOS 版本 10 中是否有任何要添加的内容或我的代码中有任何错误?
【问题讨论】:
-
在后台时,您是否仅在 iOS 10 或所有其他版本中没有收到此信息?
-
@AL。仅 iOS 10 不接收
-
把你的代码发给我,我会解决问题的。
-
@user3182143 在 ios 10 中,我们需要添加新的代理来处理推送通知。我的问题是如果我已经在应用商店中有一个应用会发生什么。推送通知无法正常工作?
-
是的。对于 iOS 10,它不起作用。如果他们在 iPhone 上安装 iOS 10,它将不起作用。您还需要根据 iOS 10 编写推送编码。
标签: ios objective-c firebase firebase-cloud-messaging firebase-notifications