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 dateByAddingTimeInterval:period];
            NSLog(@"%d",period);
            notification.timeZone=[NSTimeZone defaultTimeZone];

    //设置提醒声音为默认的声音

    //notification.soundName=UILocalNotificationDefaultSoundName;    

            notification.soundName = @" ping.caf"; //设置显示声音
            //notification.alertBody=@"TIME!";            
            notification.alertBody = [NSString stringWith Format:@"@% 时间到了!",nameStr];//显示的提示信息            
            NSDictionary*  info = [NSDictionary dictionaryWithObject:uniqueCodeStr forKey:CODE];
            notification.userInfo = info;            
            [[UI Application 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];







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值