Моих IOS приложения перестало получать уведомление толчка, хотя я модернизировал код в соответствии с документациями и this.уведомление Push-перестало работать на прошивке 8
Вот код, я использую:
В моих AppDelegate's
didFinishLaunchingWithOptions
:
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
}
Метод didRegisterForRemoteNotificationsWithDeviceToken
получил название, как было раньше, поэтому все кажется прекрасным.
Кроме того, мое тестовое устройство имеет уведомления.
Но при отправке толчка от Parse.com
он больше не поступает.
РЕДАКТИРОВАТЬ 1:
Ни один из ответов не работает. Я обновил свою инфраструктуру Parse.com до версии 1.6.2 (последняя), которая тоже не помогает, и я снова копирую свой код - на этот раз обновленная версия основана на ответах:
Внутри didFinishLaunchingWithOptions
:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
// [application registerForRemoteNotifications];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
и эти методы делегата:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken CALLED");
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
[currentInstallation addUniqueObject:@"Test8Channel" forKey:@"channels"];
if([PFUser currentUser]/* && [[PFUser currentUser] objectId] != nil*/) {
[currentInstallation addUniqueObject:[PFUser currentUser] forKey:kOwnerKey];
}
[currentInstallation saveInBackground];
}
#ifdef IS_OS_8_OR_LATER
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[application registerForRemoteNotifications];
NSLog(@"didRegisterUserNotificationSettings CALLED");
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString*)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler {
NSLog(@"handleActionWithIdentifier CALLED");
//handle the actions
if ([identifier isEqualToString:@"declineAction"]){
NSLog(@"handleActionWithIdentifier %@", @"declineAction");
}
else if ([identifier isEqualToString:@"answerAction"]){
NSLog(@"handleActionWithIdentifier %@", @"answerAction");
}
}
#endif
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
if (error.code == 3010) {
NSLog(@"Push notifications are not supported in the iOS Simulator.");
} else {
// show some alert or otherwise handle the failure to register.
NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
}
}
Оба didRegisterUserNotificationSettings
и didRegisterForRemoteNotificationsWithDeviceToken
становятся называются и, кажется, хорошо. Но толчок не приходит.
EDIT 2:
Я заметил, что если я позвоню как
[application registerUserNotificationSettings:settings];
и
[application registerForRemoteNotifications];
внутри если ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
делегата didRegisterForRemoteNotificationsWithDeviceToken
становится вызывается дважды , Я не уверен, насколько это значимо.
Отчаяние здесь.
как вы отправляете с консоли i.e, plain text/json? и ожидаете ли вы его получить на заднем плане или переднем плане? – soulshined
Я беру по умолчанию, это обычный текст, и я пробовал как на заднем плане, так и на переднем плане. Я также поместил printf в метод didReceiveRemoteNotification, но он не вызван. – Eddy
И профили или сертификаты обеспечения не были изменены? – soulshined