我正在制作一个应用程序,我想在其中实现apple推送通知服务.我按照本教程中给出的分步说明进行操作.
但仍然没有调用这些方法.我不知道造成这个问题的原因.谁能帮我?
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//NSString * token = [[NSString alloc] initWithData:deviceTokenencoding:NSUTF8StringEncoding];
NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(@"Device Token:%@",str);
//NSLog(@"Device token is called");
//const void *devTokenBytes = [deviceToken bytes];
//NSLog(@"Device Token");
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(@"Error:%@",str);
}
Run Code Online (Sandbox Code Playgroud) 我按照这个线程,但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 …Run Code Online (Sandbox Code Playgroud)