iOS技术点:判断用户是否开启推送开关/是否允许推送?
来源:互联网 发布:淘宝天猫购物券。 编辑:程序博客网 时间:2024/06/11 22:00
http://www.51itong.net/ios-12266.html
- (BOOL)isAllowedNotification{ //iOS8 check if user allow notification <span style="white-space:pre"></span>if (IS_IOS_8) {// system is iOS8 UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings]; <span style="white-space:pre"></span>if (UIUserNotificationTypeNone != setting.types) { <span style="white-space:pre"></span>return <span style="white-space:pre"></span>YES;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>} <span style="white-space:pre"></span>else <span style="white-space:pre"></span>{//iOS7 <span style="white-space:pre"></span>UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; <span style="white-space:pre"></span>if(UIRemoteNotificationTypeNone != type) <span style="white-space:pre"></span>return <span style="white-space:pre"></span>YES;<span style="white-space:pre"></span>} <span style="white-space:pre"></span>return <span style="white-space:pre"></span>NO;}
(iOS8中 用户开启的推送通知类型 对应的是 UIUserNotificationType (下边代码中 UIUserNotificationSettings 的types属性的类型) ,iOS7对应的是 UIRemoteNotificationType)
此处以iOS8的UIUserNotificationType为例,(如下图)当本地通知或push/远程通知 推送时,这个常量指明了app如何去提醒用户(比如:Badge,Sound,Alert的组合)
那么如何获得呢,在iOS8中是通过types属性,[[UIApplication sharedApplication] currentUserNotificationSettings].types
如上图,获得之后,我们要知道的是这个property储存了所有你指定的推送类型(Badge,Sound,Alert),而在图一中我们知道了推送类型对应的bitmask:(以四位二进制为例)
UIUserNotificationTypeNone = 0 , == 0000 0
UIUserNotificationTypeBadge = 1 << 0 , == 0001 1左移0位 2^0 = 1
UIUserNotificationTypeSound = 1 << 1 , == 0010 1左移1位 2^1 = 2
UIUserNotificationTypeAlert = 1 << 2 , == 0100 1左移2位 2^2 = 4
(以前老师教c语言的时候说过,还可以把左移当做乘2,右移除2)
假如用户勾选推送时显示badge和提示sound,那么types的值就是3(1+2) == 0001 & 0010 = 0011 == 2^0 + 2 ^1 = 3
- iOS技术点:判断用户是否开启推送开关/是否允许推送?
- iOS技术点:判断用户是否开启推送开关/是否允许推送?
- iOS技术点:判断用户是否开启推送开关/是否允许推送?
- iOS 判断是否允许app消息推送
- 判断是否开启推送
- iOS怎么判断用户是否打开了系统设置里面推送通知的开关?
- IOS学习笔记11-如何判断推送开关是否打开
- ios是否开启推送通知
- iOS开发——判断用户是否开启了应用推送设置
- iOS开发检测是否开启定位、是否允许消息推送等权限
- 判断iOS的推送是否打开
- JPush极光推送问题,用户是否打开允许推送信息的开关,但不管设置没设置都会弹出警告说没有设置
- iOS判断消息推送开关
- IOS中判断软件消息推送是否打开
- iOS应用内判断推送开发是否打开
- iOS开发之判断用户是否打开APP通知开关
- iOS 判断用户是否允许接收远程通知
- 检测是否开启推送通知功能
- MySQL存储引擎--MyISAM与InnoDB区别
- 初步探究ES6之for循环和Map,Set
- 带你玩转Visual Studio——Property Manager的配制
- RMI是什么?
- 【LBS】移动互联网基于LBS地理位置应用开发必备
- iOS技术点:判断用户是否开启推送开关/是否允许推送?
- 关于北京计算机技术与软件专业技术资格(水平)考试(软考)报名及证书的领取
- virsh命令中使用qemu-monitor-command
- android EditText中的inputType
- 带你玩转Visual Studio——incremental linking(增量链接)的作用
- Linux安装graphite:cannot open shared object file: No such file or directory
- 今天开始记录自己的工作学习中的技术知识
- git使用
- 保持 EditText 的简洁 ——在 Android 中对你所有的 EditText 实现文本监听