Attempting to badge the application icon but haven't received permission from the user to badge the
来源:互联网 发布:linux shell 循环 编辑:程序博客网 时间:2024/04/27 14:25
(1)原因
一切都是iOS8捣的鬼。您如果把模拟器换成iOS7.1或者更早的,就不会有这个问题。而现在在iOS8中要实现badge、alert和sound等都需要用户同意才能,因为这些都算做Notification“通知”,为了防止有些应用动不动给用户发送“通知”骚扰用户,所以在iOS8时,要“通知”必须要用户同意才行。
(2)解决思路:我们判断一下,如果系统版本大于等于8.0的话,我们就在用户打开应用的时候弹出一个框框提示说我们要发送通知给你,你同意不?如果用户同意,那么我们就可以了。而如果系统版本小于8.0的话,因为默认是可以的,所以我们不需要做任何事情。
那么问题来了:怎么弹个框框给用户,并且用户同意让我们发通知呢?
——首先这个是在应用程序第一次被打开加载完毕的时候就要弹出这个框,安装过APP的人都不会陌生吧。所以,需要在AppDelegate.m的didFinishLaunching方法中写。
——其次,我们判断系统版本,用if语句,获取系统版本,把NSString转换成float可以比较,这些都没问题。
——最终,核心是if里面的三句话。大体意思是,我们先定义一个“通知设置”,然后把这个“通知设置”注册到“用户通知设置”里面,而注册到“用户通知设置”里面的那些“通知设置”,都是用框框弹出来让用户决定是否接受这种通知的。
——这个“通知设置”,主要是定义“通知类型”。我们本例中只是badge,但是还有alert和sound都属于通知类型,所以我们“多此一举”,把所有的通知类型都囊括进来,这样,我们就不需要以后一个一个的去设置alert和sound了。
在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中,加入以下代码
CGFloat systemVersion = [[UIDevicecurrentDevice].systemVersionfloatValue];
if (systemVersion >= 8.0) {
UIUserNotificationType type =UIUserNotificationTypeBadge | UIUserNotificationTypeAlert |UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:typecategories:nil];
[[UIApplicationsharedApplication] registerUserNotificationSettings:settings];
}
原文地址:http://www.tuicool.com/articles/FjAF7za
- Attempting to badge the application icon but haven't received permission from the user to badge the
- Attempting to badge the application icon but haven't received permission from the user to badge the
- Attempting to badge the application icon but haven't received permission from the user to badge the
- Attempting to badge the application icon but haven't received permission from the user to badge the
- 解决Attempting to badge the application icon but haven't received permission from the user to badge th
- Swift之Attempting to badge the application icon but haven't received permission from the user to badg
- 【iOS开发-71】解决方案:Attempting to badge the application icon but haven't received permission from the...
- Attempting to badge the application icon but haven't received permission解决方案
- iOS开发错误之Attempting to badge the application icon but haven't received permiss
- iOS开发-71】解决方案:Attempting to badge the application icon but haven't received permiss...
- Attempting to badge the application icon but haven't received permiss...
- 解决方案:Attempting to badge the application icon but haven't received permiss...
- Attempting to badge the application icon but haven't received permiss
- 应用图标提示设置applicationIconBadgeNumber Attempting to badge the application icon but haven't
- iOS 注册通知失败 with an alert but haven't received permission from the user to display alerts
- Is there a way to add a badge to an application icon in Android?
- How to set the QT Application icon in the windows.
- [ERROR] You have enabled the binary log, but you haven't provided the mandatory server-id.
- [c]poj1009
- Uri转化为filepath的方法,及压缩图片的方法
- Handler详解之四
- Eclipse Java EE IDE for Web Developers.配置Tomcat全攻略
- 高并发 高负载 网站系统架构
- Attempting to badge the application icon but haven't received permission from the user to badge the
- testng 失败自动截图
- iLeGeND
- mysql多表联查
- 《三体》读后感
- 自定义View
- 二维码识别项目——数据库建立及报表生成
- Maven 坐标和依赖
- 输入框和键盘