首页 > 其他 > 详细

UILocalNotification

时间:2014-03-08 06:08:44      阅读:459      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm:ss"];
    // 触发通知的时间
    NSDate *now = [formatter dateFromString:@"15:04:00"];
    notification.fireDate = now;
    // 设置时区,默认即可
    notification.timeZone=[NSTimeZone defaultTimeZone];
    // 通知重复提示的单位,可以是天、周、月
    notification.repeatInterval = NSDayCalendarUnit;
    // 通知内容
    notification.alertBody = @"这是一个新的通知";
    // 通知被触发时播放的声音
    notification.soundName = UILocalNotificationDefaultSoundName;
    // 设置IconBadgeNumber
    notification.applicationIconBadgeNumber = [[[UIApplication sharedApplication] scheduledLocalNotifications] count]+1;
    // 设置本地通知发送的消息,这个消息可以接受
    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil];
    notification.userInfo = infoDict;
    //执行通知注册
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
self.window
= [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } // 应用收到通知时,会调到下面的回调函数 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"LocalNotification" message:notification.alertBody delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; //这里可以接受到本地通知中心发送的消息 NSDictionary* dic = notification.userInfo; // 图标上的数字减1 application.applicationIconBadgeNumber -= 1; NSLog(@"user info = %@",[dic objectForKey:@"key"]); }
bubuko.com,布布扣

UILocalNotification,布布扣,bubuko.com

UILocalNotification

原文:http://www.cnblogs.com/joesen/p/3586513.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!