直到今天早上,所有的设备都工作得很好,我需要设备令牌,当我在didRegisterForRemoteNotificationsWithDeviceToken设备上调试时,设备令牌就会继续前进,didFailToRegisterForRemoteNotificationsWithError方法也不会被触发。我真的很感谢你的帮助。我的代码如下。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[application registerUserNotificationSettings:mySettings];
//[application registerForRemoteNotifications];
}else{
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken);
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSString *deviceID = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
deviceID = [deviceID stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"Device_Token -----> %@\n",deviceID);
[[NSUserDefaults standardUserDefaults] setObject:deviceID forKey:@"KiviDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Error: %@", error.description);
if (error.code == 3010) {
NSLog(@"Push notifications are not supported in the iOS Simulator.");
} else {
NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
}
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
NSLog(@"NotificationSettings: %@", notificationSettings);
//register to receive notifications
[application registerForRemoteNotifications];
}
我已经检查了iOS设置应用程序通知是否启用,该方法不会被调用。
如果既没有调用委托回调application:didRegisterForRemoteNotificationsWithDeviceToken:,也没有调用application:didFailToRegisterForRemoteNotificationsWithError:,那么我需要为“故障排除推送通知”提供一些帮助,因为还没有建立连接,所以NotificationSettings没有被调用。
发布于 2016-07-19 15:00:01
苹果上一直有问题,以APNS结尾。出于某种原因,生产中的应用程序可以正常工作,但是人们正在开发的应用程序不会推动任何通知。
https://stackoverflow.com/questions/38462025
复制相似问题