ios海哥开发笔记 (海哥原创,UILocalNotification本地通知的设置以及iOS9通知新特性 )
2016-03-10 14:43
471 查看
注意:Xcode7,iOS9 ,为什么同样的一段代码在iOS8中能弹出本地通知,现在不行了呢 ,不要急,慢慢往下看吗?
一。介绍,一个APP发送本地通知是非常常见的,小编就简单介绍下本地通知
想要获取用户权限,要添加以下代码在AppDelegate.m文件中。
- (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert
| UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:setting];
return
YES;
}
1.现在一个个介绍作用了,苹果是非常在意用户体验的,所以现在开始,本地通知的内容都要一一显示
UIUserNotificationTypeNone 表示不推送
UIUserNotificationTypeBadge 表示接受图标右上角的数值改变
UIUserNotificationTypeSound 表示接受声音
UIUserNotificationTypeAlert 表示接受提醒(横幅/弹窗)
你想要获取用户哪几种权限,全部写上即可,中间用” | ” 符号隔开。
二,剩下的就是开启本地通知的代码了
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertAction = @"开始玩游戏"; //
操作标题
notification.alertBody = @"您已经一天没查看了,是上了天堂了吗";
notification.applicationIconBadgeNumber = 8;// 提醒数字
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];// 几秒后弹出通知
// notification.repeatInterval = 2;
// 注册通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
这样就能轻松解决本地通知问题了,建议扒一扒UILocalNotification的API,就那几个属性,一一了解呗。
转发请注明出处。
一。介绍,一个APP发送本地通知是非常常见的,小编就简单介绍下本地通知
想要获取用户权限,要添加以下代码在AppDelegate.m文件中。
- (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert
| UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:setting];
return
YES;
}
1.现在一个个介绍作用了,苹果是非常在意用户体验的,所以现在开始,本地通知的内容都要一一显示
UIUserNotificationTypeNone 表示不推送
UIUserNotificationTypeBadge 表示接受图标右上角的数值改变
UIUserNotificationTypeSound 表示接受声音
UIUserNotificationTypeAlert 表示接受提醒(横幅/弹窗)
你想要获取用户哪几种权限,全部写上即可,中间用” | ” 符号隔开。
二,剩下的就是开启本地通知的代码了
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertAction = @"开始玩游戏"; //
操作标题
notification.alertBody = @"您已经一天没查看了,是上了天堂了吗";
notification.applicationIconBadgeNumber = 8;// 提醒数字
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];// 几秒后弹出通知
// notification.repeatInterval = 2;
// 注册通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
这样就能轻松解决本地通知问题了,建议扒一扒UILocalNotification的API,就那几个属性,一一了解呗。
转发请注明出处。
相关文章推荐
- TF/IDF(term frequency/inverse document frequency)
- <学习笔记> require模块(省市区下拉控件)
- NGUI具有流光效果的UISprite
- 《iOS Human Interface Guidelines》——Activity
- 基于modern ui for wpf的在线公开课平台 之一(说在前面)
- Java基础之GUI
- 1099. Build A Binary Search Tree (30)
- UITableView的段头设置
- 系统启动过程中出现:error: no such partition grub rescue
- UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- java for循环跳出(break)/结束本次(continue)多重循环
- EasyTouch与UGUI的结合使用
- 快速排序实现(QuickSort)
- 使UITableViewCell之间的cell不显示分割线
- easyui tree的简单使用
- 自定义View--------Android UI模板设计
- iOS UILabel自适应高度宽度
- 让UITextField只能输入数字以及限制长度
- DUILIB项目中自定义快捷键功能的实现方法
- 关于UINavigationController — navigationBar