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

查看:21
本文介绍了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


如果您需要重置推送通知设置和权限警报,请查看 Apple 技术说明 TN2265.在在 iOS 上重置推送通知权限警报"部分,他们解释了如何在 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.

我自己想知道 Apple 是否已经删除了 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),但不能检查特定应用程序的推送通知是否启用或禁用(顶部的通知中心 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天全站免登陆