博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
定时提醒实现
阅读量:7120 次
发布时间:2019-06-28

本文共 1372 字,大约阅读时间需要 4 分钟。

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
{
}
一样的处理方法。

转载于:https://www.cnblogs.com/cdp-snail/p/5194886.html

你可能感兴趣的文章
Python OpenCV学习笔记之:使用MOG2视频背景消除
查看>>
8月第三周网络安全:境内感染网络病毒主机数73.7万个
查看>>
【Android】Service生命周期回顾
查看>>
11月国内浏览器市场份额:IE、Chrome均遭蚕食
查看>>
Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
查看>>
【公开课视频】ASP.NET MVC+EF入门-20130315
查看>>
Thinkphp 公共函数自动加载
查看>>
Linux内核之数据双链表
查看>>
【云计算的1024种玩法】巧用迁云工具轻松实现服务器迁移到ECS
查看>>
MaxCompute,基于Serverless的高可用大数据服务
查看>>
Linux下MySQL表名区分大小写
查看>>
mysql主从配置
查看>>
《算法图解》之散列表
查看>>
golang for switch break 使用
查看>>
PHP自己实现var_dump函数
查看>>
A simple poem
查看>>
故事板控件无法和代码关联的问题解决
查看>>
锁分段技术、ConcurrentHashMap、扩容
查看>>
恭喜51CTO视频课程认证讲师、博主李海园喜得姐妹花
查看>>
我的友情链接
查看>>