私はこのスレッドに従いましたが、メソッドdidRegisterForRemoteNotificationsWithDeviceToken
はまだ呼び出されていません:
ドキュメントには次のように書かれています:
UIApplication オブジェクトの registerForRemoteNotifications メソッドを呼び出した後、デバイスの登録が正常に完了すると、アプリはこのメソッドを呼び出します
didRegisterUser
よく見えますが、そうではありませんdid register notif
。
これがAppDelegateの私のコードです(アプリのバージョンは8.1です):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//register notif
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
return YES;
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
//register to receive notifications
[application registerForRemoteNotifications];
NSLog(@"didRegisterUser");
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"error here : %@", error);//not called
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
/*
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
currentInstallation.channels = @[ @"global" ];
[currentInstallation saveInBackground];
*/
NSLog(@"did register notif");//not called
}
info.plist にバックグラウンド モード -> リモート通知もあります。