错误内容
Attempting to schedule a local notification <UIConcreteLocalNotification: 0x15686ff0>{fire date = 2015年2月26日 星期四 中国标准时间下午3:14:57, time zone = Asia/Shanghai (GMT+8) offset 28800, repeat interval = NSCalendarUnitDay, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = 2015年2月26日 星期四 中国标准时间下午3:14:57, user info = {key = name;
}} with a badge number but haven't received permission from the user to badge the application
问题原因
iOS8要实现badge、alert和sound等都需要用户同意才能进行。
解决方案
先注册一下通知,弹出对话框,用户同意后,就能进行本地推送了。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//处理iOS8本地推送不能收到
float sysVersion=[[UIDevice currentDevice]systemVersion].floatValue;
if (sysVersion>=8.0) {
UIUserNotificationType type=UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication]registerUserNotificationSettings:setting];
}
return YES;
}