在“设置”中的读取通知标志应用程序在我的iPhone应用程序 [英] Reading Notification flag in "Settings" application inside my iPhone application

查看:193
本文介绍了在“设置”中的读取通知标志应用程序在我的iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用启用推送通知。当我的应用程序运行时,如何在设置应用程序中读取通知的标志。由于某些原因,我需要知道某个特定通知(提醒,声音,徽章)是否设置为ON / OFF。

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.

请指导。

推荐答案

尝试引用此方法 [[UIApplication sharedApplication] enabledRemoteNotificationTypes]

它将返回一个UIRemoteNotificationType,您可以使用它来确定可用的内容。

It will return a UIRemoteNotificationType which you can work with to determine what is available.

UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

现在,状态可以使用 NSLog status =,status); ,我们可以准确地确定是什么。但是要做到这一点,我们需要了解UIRemoteNotificationType。

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.

typedef enum {
   UIRemoteNotificationTypeNone    = 0,
   UIRemoteNotificationTypeBadge   = 1 << 0,
   UIRemoteNotificationTypeSound   = 1 << 1,
   UIRemoteNotificationTypeAlert   = 1 << 2,
   UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
} UIRemoteNotificationType;

没有更多的细节,你基本上需要离开这个知道是...

Without going into much detail, what you basically need to walk away from this knowing is that ...


  • 如果徽章已开启,请添加1

  • 如果声音已开启,请添加2

  • 如果提醒已开启,请添加4

  • 如果报亭内容可用,请添加8(我不会担心此人)

  • If badges are on, add 1
  • If sound is on, add 2
  • If alerts are on, add 4
  • If Newsstand Content is available, add 8 (I'm not going to worry about this guy)

假设您想知道徽章/声音/警报是否全部开启。 UIRemoteNotificationType(如果你正在玩的状态)应该是7.

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.

现在,让我们向后工作。让我们说 status == 5 。只有一个设置配置可以给我们这个值,这是如果徽章和警报开启(徽章添加1,警报添加4,总是5),声音关闭。

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.

如果 status == 6 会怎么样?

使用IF语句,只需要一个设置,我们可以做

Using IF statements, we can do something like

If (status == 5)
{
    NSLog(@"User has sound alerts disabled");
    [self fireThatSpecialMethod];
}

要运行一组设置的代码,被禁用,但一切都开启。反正,希望这个回应对人有帮助!

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!

这篇关于在“设置”中的读取通知标志应用程序在我的iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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