iOS8中registerUserNotificationSettings的奇怪行为
我尝试在中的应用程序启动时仅注册警报类型通知iOS8中registerUserNotificationSettings的奇怪行为,ios8,apple-push-notifications,Ios8,Apple Push Notifications,我尝试在中的应用程序启动时仅注册警报类型通知 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 打电话 UIUserNotificationType types = UIUserNotificationTypeAlert; UIUserNotificationSettings *settings = [UIUserNotifi
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
打电话
UIUserNotificationType types = UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
在
我在notificationSettings
<UIUserNotificationSettings: 0x16dd6160; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>
提供相同的所有类型,尽管我最初选择了唯一的警报类型
因此,我无法在开始时设置受限的动态权限
互联网上没有关于类似问题的任何信息。您必须在
(BOOL)应用程序:(UIApplication*)应用程序完成启动时使用选项:(NSDictionary*)启动选项注册通知。
更新:
根据报告:
第一次调用registerUserNotificationSettings:方法时,
iOS会显示一个对话框,要求用户允许显示
应用程序注册的通知类型。用户回复后,iOS
使用
应用程序:didRegisterUserNotificationSettings:方法,传递
UIUserNotificationType对象,该对象指定
用户允许的通知
用户可以随时使用更改其通知设置
设置应用程序。您的应用程序将在安装后立即添加到设置应用程序
调用注册表通知设置:。用户可以启用或禁用
通知,以及修改通知的位置和方式
提出了。因为用户可以随时更改其初始设置
时间,请在执行任何工作之前调用currentUserNotificationSettings
准备提交通知
所以,若用户已经接受了通知设置,应用程序将无法更改它们
currentUserNotificationSettings
始终显示当前用户设置,而不是应用程序设置。似乎无法在iOS8(至少)中从应用程序设置UserNotificationType
。您需要使用通用通知中心设置声音、徽章和警报的任意组合。仅第一次尝试注册时,需要推送通知权限警报集UserNotificationType
另一种方法是在订阅时向推送服务器发送
UserNotificationType
,推送服务器应使负载取决于此类型。-(void)application:(UIApplication*)application didRegisterUserNotificationSettings:(UIUserNotificationSettings*)notificationSettings
只是在注册表notificationSettings之后调用的回调,请参见我答案中的更新
<UIUserNotificationSettings: 0x16dd6160; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings]