+ (void)registerLocalNotification:(NSDictionary *)dic
{
NSString *fireDateStr =[dic objectForKey:@"fireDate"];
NSInteger fireDate = [fireDateStr intValue];
NSString *alertBody = [dic objectForKey:@"alertBody"];
NSString *alertAction = [dic objectForKey:@"alertAction"];
NSString * badgeNumberStr =[dic objectForKey:@"badgeNumber"];
NSInteger badgeNumber = [badgeNumberStr intValue];
NSString *keyName = [dic objectForKey:@"keyName"];
NSInteger notificationtag =[dic objectForKey:@"notificationtag"];
UILocalNotification *notification=[[UILocalNotification alloc] init];
if (notification!=nil) {
//使用本地时区
notification.timeZone=[NSTimeZone timeZoneWithAbbreviation:@"GMT+0800"];//[NSTimeZone defaultTimeZone];
NSDate *notifyTime = [NSDate dateWithTimeIntervalSinceNow:fireDate];//触发的时间
//从现在开始,10秒以后通知
notification.fireDate=notifyTime;
notification.alertBody=alertBody;//@"顶部提示内容,通知时间到啦";
//通知提示音 使用默认的
notification.soundName= UILocalNotificationDefaultSoundName;
notification.alertAction=NSLocalizedString(alertAction, nil);//@"你锁屏啦,通知时间到啦"
//这个通知到时间时,你的应用程序右上角显示的数字。
notification.applicationIconBadgeNumber = badgeNumber;
//add key 给这个通知增加key 便于半路取消。nfkey这个key是我自己随便起的。
// 假如你的通知不会在还没到时间的时候手动取消 那下面的两行代码你可以不用写了。
NSDictionary *dict =[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:notificationtag],keyName,nil];
[notification setUserInfo:dict];
//启动这个通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
//这句真的特别特别重要。如果不加这一句,通知到时间了,发现顶部通知栏提示的地方有了,然后你通过通知栏进去,然后你发现通知栏里边还有这个提示
//除非你手动清除,这当然不是我们希望的。加上这一句就好了。网上很多代码都没有,就比较郁闷了。
[notification release];
}
}