UILocalNotification实现本地的闹钟提醒的方法

本文详细介绍了如何使用 iOS 的 UILocalNotification 进行本地通知的设置与处理,包括通知的触发时间设定、信息传递及应用内处理方式等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[html]  view plain copy
  1.         UILocalNotification *notification=[[UILocalNotification alloc] init];  
  2.         if (notification!=nil)  
  3.         {  
  4.               
  5.             NSDate *now=[NSDate new];  
  6.              
  7.             //notification.fireDate=[now addTimeInterval:period];  
  8.             notification.fireDate = [now dateByAddingTimeInterval:period];  
  9.             NSLog(@"%d",period);  
  10.             notification.timeZone=[NSTimeZone defaultTimeZone];  
  11.             notification.soundName = @"ping.caf";  
  12.             //notification.alertBody=@"TIME!";  
  13.               
  14.             notification.alertBody = [NSString stringWithFormat:@"@%时间到了!",nameStr];  
  15.               
  16.             NSDictionary* info = [NSDictionary dictionaryWithObject:uniqueCodeStr forKey:CODE];  
  17.             notification.userInfo = info;  
  18.               
  19.             [[UIApplication sharedApplication] scheduleLocalNotification:notification];        
  20.               
  21.         }  
  22.   
  23. 设置的时间到了以后,会自动在桌面弹出一个提示框,点显示后,就可以启动软件。然后在  
  24. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  25. {  
  26.     UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];  
  27.     if (localNotif)  
  28.     {  
  29.         NSLog(@"Recieved Notification %@",localNotif);  
  30.         NSDictionary* infoDic = localNotif.userInfo;  
  31.         NSLog(@"userInfo description=%@",[infoDic description]);  
  32.         NSString* codeStr = [infoDic objectForKey:CODE];  
  33.     }  
  34. }里,对lanchOptions进行处理,找到它里面的信息,就可以拿到设置时的需要处理的东西,就可以继续操作了。  
  35.   
  36. 如果此时你的客户端 软件仍在打开,则会调用  
  37. - (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif  
  38. {  
  39.   
  40. }  
  41. 一样的处理方法。  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值