Objective-C-检测用户何时更改应用程序的通知设置 [英] Objective-C - Detect when user change the app's notifications settings

查看:77
本文介绍了Objective-C-检测用户何时更改应用程序的通知设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要始终知道用户在推送通知设置中选择了哪些选项.
(选项为-警报,声音和徽章)

I need to always know which options the user choose on the push notification settings.
(The options are - alert, sound and badges)

因此,当我的应用启动时,我会致电:

So when my app launch I call:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

并检测用户选择了什么.

and detect what the user chose.

但是如何在应用程序生存期内检测用户是否更改了设置?
对此设置进行更改时,是否有某些委托方法被调用?

But how can I detect if the user change the settings later during the app life time?
Is there some delegate method that get called when a change occur with this settings?

推荐答案

没有委托.您需要定期查询UIApplication属性enabledRemoteNotificationTypes,例如在applicationDidBecomeActive:中.

There is no delegate. You need to query the UIApplication property enabledRemoteNotificationTypes periodically, for example in applicationDidBecomeActive:.

有关详细信息,请检查以下答案:

For details check these answers:

在iPhone上确定用户是否已启用推送通知

在锁屏中查看和enabledRemoteNotificationTypes-iOS5

修改:
如果您需要重置推送通知设置和权限警报,请查看部分中,他们说明了如何在iOS上重置设置.但是,许多开发人员抱怨该过程不起作用.不确定此链接是否有效,您需要访问Apple论坛,但这是有关此确切问题的话题之一.


If you need to reset the push notification setting and the permission alert, have a look at the Apple technical note TN2265. In section "Resetting the Push Notifications Permissions Alert on iOS" they explain how to reset the setting on iOS. However, many developers complain that the procedure doesn't work. Not sure if this link will work, you will need to have access to the Apple forum, but it is one of the threads about this exact issue.

我本人想知道苹果是否已在iOS 5.1中删除了权限对话框.否则,为什么他们会要求应用程序显示警报?根据 AppStore审查指南直到2016年6月:

I was myself wondering if maybe Apple has removed the permission dialog in iOS 5.1. Otherwise why would they require the application to show the alert? According to AppStore review guidelines until June 2016:

5.3 在未先征得用户同意的情况下发送推送通知的应用将被拒绝

5.3 Apps that send Push Notifications without first obtaining user consent will be rejected

例如,Path(应用程序)要求用户在启动过程中选择加入推送通知,而不是在应用程序首次启动时.

For example Path (application) asks the user to opt-in for push notification in the middle of the sing-up process, not when the application starts for the first time.

不确定该提示的目的是什么,因为该应用程序无法查询通知设置的状态.特别是,该应用程序可以检查启用了哪些通知类型(使用enabledRemoteNotificationTypes),但不能检查是否启用或禁用了特定应用程序的推送通知(顶部的Notification Center ON/OFF开关).至少这是iOS 5.1中的行为.即使用户禁用了该应用程序的通知,该应用程序仍可以注册推送通知(使用registerForRemoteNotificationTypes),并且将收到APNS令牌.

Not sure what should be the purpose of the prompt anyway as the application can't query the state of the notification setting. In particular, the application can check which notification types (using enabledRemoteNotificationTypes) are enabled but NOT if push notifications for a particular application are enabled or disabled (the Notification Center ON/OFF switch at the top). At least that's the behavior in iOS 5.1. Even if user disables notifications for that application, the application can still register for push notifications (using registerForRemoteNotificationTypes) and WILL receive an APNS token.

这篇关于Objective-C-检测用户何时更改应用程序的通知设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆