zoukankan      html  css  js  c++  java
  • 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"]); }
  • 相关阅读:
    简单地通过Python库使用python的socket编程
    js 实现继承的几种方式
    JAVA中获取当前系统时间
    IntelliJ Idea 常用快捷键列表
    关于报错:There is already 'xxxController' bean method的解决方法
    mysql 使用 GROUP BY 时报错 ERROR 1055 (42000)
    安装系统,用cmd进行分区
    Bootstrap关闭当前页
    bootstrap的日期选择器
    Bootstrap如何关闭弹窗
  • 原文地址:https://www.cnblogs.com/joesen/p/3586513.html
Copyright © 2011-2022 走看看