标签:我的文章
//本地通知,只有在程序处于非运行状态下,才会发送本地通知
//1.创建本地的通知对象
UILocalNotification *notification = [[UILocalNotification alloc] init];
//2.设置通知触发的时间
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
//3.设置弹出的提示内容
notification.alertBody = @"消息来了,赶紧去看看吧";
//4.设置按钮的标题
notification.alertAction = @"提醒";
//注册本地通知,注册之后,通知才会生效
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[UIApplication sharedApplication].applicationIconBadgeNumber = 3;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//在iOS8中,本地通知需要添加以下代码才能正确运行-----得到用户的允许推送通知
UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:setting];
return YES;
}
//点击了弹出的通知后,才会调用下面的方法
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"App通过本地通知打开了");
application.applicationIconBadgeNumber = 0;
}
标签:我的文章
原文地址:http://10585085.blog.51cto.com/10575085/1703037