zoukankan      html  css  js  c++  java
  • UILocalNotification实现本地的闹钟提醒的方法。

    http://www.devdiv.com/thread-69786-1-1.html

    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
    {

    }
    一样的处理方法。


    在程序中取消已经设定的通知的方法了:
    NSString *myIDToCancel = @"some_id_to_cancel"; 
    UILocalNotification *notificationToCancel=nil; 
    for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) 
    {   
    if([aNotif.userInfo objectForKey:@"ID"] isEqualToString:myIDToCancel]) 
    {      
    notificationToCancel=aNotif;    
      break;   


    [[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];

  • 相关阅读:
    年末反思
    Flink运行时架构
    Phoenix 启动报错:Error: ERROR 726 (43M10): Inconsistent namespace mapping properties. Cannot initiate connection as SYSTEM:CATALOG is found but client does not have phoenix.schema.
    Clickhouse学习
    Flink简单认识
    IDEA无法pull代码到本地,Can't Update No tracked branch configured for branch master or the branch doesn't exist.
    第1章 计算机系统漫游
    简单的 Shell 脚本入门教程
    开源≠免费 常见开源协议介绍
    MySQL 视图
  • 原文地址:https://www.cnblogs.com/ligun123/p/2252882.html
Copyright © 2011-2022 走看看