ios 本地通知

来源:互联网 发布:吃饭排队叫号软件 编辑:程序博客网 时间:2024/06/07 00:15
 UILocalNotification *notification=[[UILocalNotification alloc] init];     if (notification!=nil) {           NSDate *now = [NSDate date];             //从现在开始,10秒以后通知             notification.fireDate=[now dateByAddingTimeInterval:10];
 //notification.fireDate = [NSDate dateWithTimeIntervalSince1970:8*60*60];//8点通知             //使用本地时区             notification.timeZone=[NSTimeZone defaultTimeZone];             notification.alertBody=@"顶部提示内容,通知时间到啦";             //通知提示音 使用默认的             notification.soundName= UILocalNotificationDefaultSoundName;             notification.alertAction=NSLocalizedString(@"你锁屏啦,通知时间到啦", nil);            //这个通知到时间时,你的应用程序右上角显示的数字。            notification.applicationIconBadgeNumber = 1;             //add key  给这个通知增加key 便于半路取消。nfkey这个key是我自己随便起的。             // 假如你的通知不会在还没到时间的时候手动取消 那下面的两行代码你可以不用写了。             NSDictionary *dict =[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:notificationtag],@"nfkey",nil];             [notification setUserInfo:dict];             //启动这个通知             [[UIApplication sharedApplication]   scheduleLocalNotification:notification];            //这句真的特别特别重要。如果不加这一句,通知到时间了,发现顶部通知栏提示的地方有了,然后你通过通知栏进去,然后你发现通知栏里边还有这个提示             //除非你手动清除,这当然不是我们希望的。加上这一句就好了。网上很多代码都没有,就比较郁闷了。             [notification release];

}

//每1分钟提醒一次 
notification.repeatInterval= NSMinuteCalendarUnit; 
//每1小时提醒一次 
notification.repeatInterval= NSHourCalendarUnit; 
//每1天提醒一次 
notification.repeatInterval=NSDayCalendarUnit; 

0 0
原创粉丝点击