读取“设置”中的通知标志我的 iPhone 应用程序中的应用程序
我正在为我的应用程序启用推送通知。当我的应用程序运行时,我们如何读取“设置”应用程序中的通知标志。由于某些原因,我需要知道特定通知(警报、声音、徽章)是否设置为开/关。
请指导。
I am enabling push notification for my application. How can we read the flags for notification in "Settings" app when my app is Running. For some reasons, I need to know whether a particular notification (alert, sound, badge) is set to ON/OFF.
Please guide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试调用此方法
[[UIApplication共享应用]enabledRemoteNotificationTypes]
它将返回一个UIRemoteNotificationType,您可以使用它来确定可用的内容。
现在,可以使用 NSLog(@"status = ", status); 将状态视为 int,我们可以准确地确定正在发生的情况。但要做到这一点,我们需要了解 UIRemoteNotificationType。
无需赘述,您基本上需要了解的是...
假设您想知道徽章/声音/警报是否全部打开。 UIRemoteNotificationType(如果您正在玩的话,则为状态)应该为 7。
现在,让我们倒退一下。假设
status == 5
。只有一种设置配置可以为我们提供此值,即徽章和警报是否打开(徽章加 1,警报加 4,总计为 5)并且声音关闭。如果
status == 6
怎么办?同样,只有一种设置配置会返回此数字,即警报和声音均打开,而徽章关闭。使用 IF 语句,我们可以执行类似的操作
:运行一组代码,或者在禁用声音但其他一切都打开时触发特定方法。无论如何,希望这个回答对人们有所帮助!
Try evoking this method
[[UIApplication sharedApplication] enabledRemoteNotificationTypes]
It will return a UIRemoteNotificationType which you can work with to determine what is available.
Now, status can be looked at as an int using
NSLog(@"status = ", status);
, to which we can determine exactly what is on. But to do this we need to understand UIRemoteNotificationType.Without going into much detail, what you basically need to walk away from this knowing is that ...
Let's say you want to know if badges/sound/alerts are all on. The UIRemoteNotificationType (status if you are playing along) should come out to be 7.
Now, lets work backwards. Lets say that
status == 5
. There is only one configuration of settings that can give us this value, and that is if badges and alerts are on (badges add 1, alerts add 4, total is 5) and sound is off.What if
status == 6
? Again, there is only one configuration of settings that will return this number, and that is if alerts and sound are both on, while badges are off.Using IF statements, we can do something like
To run a set block of code, or fire a particular method for when sound is disabled, but everything else is on. Anyways, hope this response is helpful to people!
请注意,从 iOS 8 开始,您正在寻找的确定远程通知是否已注册的方法如下:
您可以使用以下方法确定用户当前启用的通知类型 :以下方法
将返回一个包含您需要的所有信息的 UIUserNotificationSettings 对象。
文档链接:
isRegisteredForRemoteNotifications
currentUserNotificationSettings
UIUserNotificationSettings
Note that as of iOS 8 the method you are looking for to determine if remote notifications are registered is this:
You may determine what kinds of notifications the user currently has enabled using the following method
This returns a UIUserNotificationSettings object with all of the info you need.
Documentation Links:
isRegisteredForRemoteNotifications
currentUserNotificationSettings
UIUserNotificationSettings