• 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"]); }
  • 相关阅读:
    bzoj2301: [HAOI2011]Problem b懵逼乌斯反演
    bzoj3504: [Cqoi2014]危桥 网络流
    bzoj1588: [HNOI2002]营业额统计 splay瞎写
    bzoj1008快速面
    洛谷1212手动枚举各种情况(缩代码成瘾)
    bzoj1968真·想sha法bi题
    bzoj3674同上(好短)
    bzoj3673可持久化线段树实现可持久化数组实现可持久化并查集(好长)
    uoj98未来程序改 纯暴力不要想了
    bzoj3680模拟退火
  • 原文地址:https://www.cnblogs.com/joesen/p/3586513.html
Copyright © 2020-2023  润新知