用的是xcode8,看下面的代码,还需要设置什么东西么,运行在iPhone 7上
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIWindow * window = [[UIWindow alloc]init];
window.frame = [UIScreen mainScreen].bounds;
self.window.rootViewController = [[ViewController alloc]init];
[window makeKeyWindow];
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
UILocalNotification * notification = [[UILocalNotification alloc]init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];//10秒后触发
notification.repeatInterval = 2; //重复次数
//设置通知的一些属性
notification.alertBody = @"有一条新的消息请注意查收";//通知主题,外部显示的内容
notification.alertTitle = @"新的消息";
notification.applicationIconBadgeNumber = 66; //应用图标右上角显示消息的个数;
notification.alertAction = @"打开应用";//待机界面的滑动动作提示
notification.alertLaunchImage = @"Default";//通过点击通知打开应用时启动的图片,这里使用的是开启应用时的图片
// notification.soundName = @""; 通知声音
//设置用户信息
notification.userInfo = @{@"id":@1,@"user":@"Yibo Wang"};//绑定到通知上的其他附加信息
//调用通知
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
return YES;
}
你那个授权方法可能失效了,改成下面这个试试
// ios8后,需要添加这个注册,才能得到授权
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
// 通知重复提示的单位,可以是天、周、月
notification.repeatInterval = NSCalendarUnitDay;
}