• UILocalNotification


    - (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;
     // 触发通知的时间
        NSDate *currDate = [NSDate date];
        NSTimeInterval  interval = 30*60; // 半个小时
        NSDate *after30minDate = [currDate initWithTimeIntervalSinceNow:+interval];
        NSString *currTime = [formatter stringFromDate:after30minDate];
        
        NSDate *notificationTme = [formatter dateFromString:currTime];
        notification.fireDate = notificationTme;
        
        notification.fireDate = [currDate dateByAddingTimeInterval:9];
    
    
    // 设置时区,默认即可
        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"]); }
  • 相关阅读:
    记录一次Centos磁盘空间占满的解决办法(转)
    Linux的php-fpm优化心得-php-fpm进程占用内存大和不释放内存问题(转)
    解决find命令报错: paths must precede expression(转)
    saltstack 使用salt ‘*’ test.ping 报错Minion did not return(转)
    Linux删除软链接
    循环队列
    正益无线首页jQuery焦点图
    基于jQuery点击缩略图右侧滑出大图特效
    基于jQuery垂直多级导航菜单代码
    带网上开户表单jQuery焦点图
  • 原文地址:https://www.cnblogs.com/joesen/p/3586513.html
Copyright © 2020-2023  润新知