zoukankan      html  css  js  c++  java
  • 定时提醒实现

    UILocalNotification *notification=[[UILocalNotification alloc] init];
            if (notification!=nil)
            {
               
                NSDate *now=[NSDate new];
              
                //notification.fireDate=[now addTimeInterval:period];
                notification.fireDate = [now dateByAddingTimeInterval:period];
                NSLog(@"%d",period);
                notification.timeZone=[NSTimeZone defaultTimeZone];
                notification.soundName = @"ping.caf";
                //notification.alertBody=@"TIME!";
               
                notification.alertBody = [NSString stringWithFormat:@"@%时间到了!",nameStr];
               
                NSDictionary* info = [NSDictionary dictionaryWithObject:uniqueCodeStr forKey:CODE];
                notification.userInfo = info;
               
                [[UIApplication sharedApplication] scheduleLocalNotification:notification];     
               
            }

    设置的时间到了以后,会自动在桌面弹出一个提示框,点显示后,就可以启动软件。然后在
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
        if (localNotif)
        {
            NSLog(@"Recieved Notification %@",localNotif);
            NSDictionary* infoDic = localNotif.userInfo;
            NSLog(@"userInfo description=%@",[infoDic description]);
            NSString* codeStr = [infoDic objectForKey:CODE];
        }
    }里,对lanchOptions进行处理,找到它里面的信息,就可以拿到设置时的需要处理的东西,就可以继续操作了。

    如果此时你的客户端 软件仍在打开,则会调用
    - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
    {

    }
    一样的处理方法。

  • 相关阅读:
    poj_3984_迷宫问题_(bfs+记录路径)
    uva_10369_mst
    HDU_1875_mst
    人工智能、机器学习和深度学习做好准备的数据中心
    网络安全需求爆发,千亿产业人才匮乏
    物联网IOT市场才起步,还要10年才成熟
    AI人士不得不了解的十大机器算法
    中国“人工智能”实力最强的5所大学
    物联网的历史:过去与未来
    人工智能进入第四代,人工直觉成为下一步发展
  • 原文地址:https://www.cnblogs.com/cdp-snail/p/5194886.html
Copyright © 2011-2022 走看看