【发布时间】:2015-12-08 17:38:19
【问题描述】:
我针对同一个问题查看了很多问题和答案。
而我现在知道的是
- 当应用处于后台时不会调用“didReceiveRemoteNotification”。
- didReceiveRemoteNotification 仅在应用程序处于前台时调用,或者当用户通过点击通知进入应用程序(如果它在后台)时调用。
- application:didFinishLaunchingWithOptions: 当用户点击通知以打开应用程序时调用它。
我的情况如下:
- 我正在使用解析来推送和获取通知。
- 当应用程序处于前台并且我正在处理数据并在通知列表中显示警报和列表通知时,我成功获得了通知。
- 但当应用程序处于后台或被终止时,我无法收到通知。
- 但是我检查了我的应用程序是否可以在我的应用程序处于后台或在使用 Parse 的“自定义受众”时根据需要被终止时收到通知。 (与其他著名应用程序一样)
我想在应用程序处于后台或被杀死时收到通知,就像我使用 Parse 的“自定义受众”时一样。 但是当我只使用 Parse 的 API 时,它不能按我的意愿工作。
我现在有什么遗漏吗?
我的注册码如下:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"didReceiveRemoteNotification executed : %@",userInfo);
NSInteger bettingIDX = [[userInfo objectForKey:@"betting_idx"] integerValue];
NSString *message = [userInfo objectForKey:@"message"];
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = [NSString stringWithFormat:@"%@",message];
NSUUID *uuid = [NSUUID UUID];
NSString *notificationKey = [uuid UUIDString];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSLog(@"DeviceToken : %@", deviceToken );
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[Parse setApplicationId:@"applicationID"
clientKey:@"clientID"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
【问题讨论】:
-
请添加您如何注册通知的代码。如果您在前台收到通知,那么您也必须在后台收到通知,请检查通知托盘。
-
@Milan 我做到了,米兰请帮忙
-
您的 iOS 代码对于在 Parse 上注册设备令牌是正确的。当应用程序进入后台时,您是否清除了令牌?另外,您如何从 Parse 发送通知?因为您在前台而不是在后台收到通知真的很奇怪。尝试检查通知托盘并在推送控制台上查看通知是否已传递。
-
@Milan 正如我上面所说,我认为您的问题毫无意义,因为当我使用自定义解析受众而不是 pase api 时,我会在应用程序处于后台或被杀时收到推送通知
-
我问这些问题只是为了帮助你,因为你没有提供太多信息,但如果你有这种态度,我很抱歉我帮不上忙。
标签: ios parse-platform push-notification apple-push-notifications