标签:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //应用图标数字 application.applicationIconBadgeNumber=6; //申请用户的许可 float version=[[[UIDevice currentDevice]systemVersion]floatValue]; if (version>8.0) { UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]; [[UIApplication sharedApplication]registerUserNotificationSettings:setting]; } UILocalNotification *localNotification=[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotification!=nil) { [self processLocationNotification:localNotification]; } return YES; } - (void)processLocationNotification:(UILocalNotification *)localNotification{ UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"lanchApp" message:@"loc" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } //注册设置提醒后 调用的代理方法 - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{ if (notificationSettings.types!=UIUserNotificationTypeNone) { //注册本地推送 首先是生成UILocalNotification对象 UILocalNotification *localNotification=[[UILocalNotification alloc]init]; //提示触发的时间 localNotification.fireDate=[NSDate dateWithTimeIntervalSinceNow:5]; //提示推送的内容 localNotification.alertBody=@"这是一个本地推送测试"; localNotification.repeatInterval=3; localNotification.repeatInterval=NSCalendarUnitMinute; //定制消息到来时候播放的声音文件 一定要在Bunddle内,而且声音的持续时间不能超过30s localNotification.soundName=@"CAT2.WV"; //设置系统角标 localNotification.applicationIconBadgeNumber=6; //注册本地通知到系统中,这样系统到指定的时间会触发该通知 [[UIApplication sharedApplication]scheduleLocalNotification:localNotification]; } } //当程序运行在后台的时候或者程序没有启动,,当注册的本地通知到达时候,ios会弹框并且播放你设置的声音 //当应用程序运行在前台的时候会调用该代理方法 不会播放声音也不会弹框 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{ //判断应用程序状态来决定是否弹框 if (application.applicationState == UIApplicationStateActive) { UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:@"本地推送" message:notification.alertBody delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; [alterView show]; }else if (application.applicationState == UIApplicationStateInactive) { NSLog(@"UIApplicationStateInactive"); }else{ //background NSLog(@"UIApplicationStateBackground"); } }
标签:
原文地址:http://my.oschina.net/u/2410306/blog/515417