UILocalNotification实现本地通知
来源:互联网 发布:网络问卷调查怎么总结 编辑:程序博客网 时间:2024/05/22 10:39
首先要注意的是:如果用户的应用程序是退出的状态,向用户推送通知后,用户点击通知进入应用程序时,会调用方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
因为程序是退出的状态,应用程序第一次启动时就会调用这个方法。
另外,注意的是,如果应用程序处于退出状态,在向用户推送通知后,用户并不是点击弹出的推送框进入程序,而是点击的软件图标进入的程序时,仍然会调用这个方法,但是不同的是:
点击推动弹出框进入程序的,launchOptions对应的字典中是有数据的,即UIApplicationLaunchOptionsLocalNotificationKey对应的是为启动应用程序的的本地通知对象(UILocalNotification);这样的话,对下面的方法中对lanchOptions进行处理,找到它里面的信息,就可以拿到设置时的需要处理的东西,就可以继续操作了。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ UILocalNotification * localNotify = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];if(localNotify) //localNotify存在的话,说明用户是通过点击推送的弹出框进入应用程序的{ } }
而如果用户是点击的软件图标进入的应用程序的话,lauchOptions内是没有数据的;所以可以通过这个区别来判断用户在程序退出状态,接受到推送通知后是通过哪种方式进入应用程序的
另外,如果你的客户端软件还在打开状态,当向用户推送消息,用户再进入软件界面时,会调用方法:
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif{}
在{}内部编写要进行的操作即可
注:
关于设置通知的相关代码:
//1.创建通知 UILocalNotification *localNote = [[UILocalNotification alloc]init]; //2.设置属性 localNote.alertAction = @"开始玩游戏";//操作标题 localNote.alertBody = @"你都好几天没来玩我了,想你了";//通知的内容,即正文 localNote.applicationIconBadgeNumber = 1;//红色图标显示的数字 localNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];//从现在开始隔多久后进行通知用户 //3.注册通知 UIApplication *app = [UIApplication sharedApplication]; [app scheduleLocalNotification:localNote];//按定制的时间设置通知 [app cancelAllLocalNotifications];//取消通知
0 0
- UILocalNotification实现本地通知
- ios-实现本地通知(UILocalNotification)
- 本地通知UILocalNotification
- UILocalNotification 本地通知
- iOS本地通知UILocalNotification
- IOS 本地通知 UILocalNotification
- ios本地通知UILocalNotification
- 本地通知UILocalNotification
- iOS UILocalNotification本地通知
- 本地通知UILocalNotification
- iOS本地通知:UILocalNotification
- UILocalNotification本地通知介绍
- 本地通知UILocalNotification
- UILocalNotification 本地通知
- 本地通知UILocalNotification
- iOS本地通知:UILocalNotification
- iOS UILocalNotification本地通知
- UILocalNotification一本地通知
- gridview中取得当前行的行号
- POJ1789【CTU Open 2003】Truck History
- Linux Shell脚本攻略(1.1)
- Gradle Build速度加快终极方法
- 求最大最小元 C++实现 分治法
- UILocalNotification实现本地通知
- hdu1212 Big Number &第六届山东省赛Single Round Math (同余定理,大数取模)
- Java数组操作的10大方法
- “正由另一进程使用,因此该进程无法访问该文件”的解决办法
- C++双向循环链表
- php multipart/form-data DOS C#测试工具
- 第九周 项目五--方程也是类
- [leetcode][tree][stack] Binary Search Tree Iterator
- IOS 整体框架类图值得收藏