Abh*_*nav 5 iphone cocoa-touch push-notification ios4
我正在为我的应用程序启用推送通知.当我的应用程序运行时,我们如何在"设置"应用程序中读取通知标志.出于某些原因,我需要知道特定通知(警报,声音,徽章)是否设置为ON/OFF.
请指导.
Nic*_*TGD 11
尝试唤起这种方法 [[UIApplication sharedApplication] enabledRemoteNotificationTypes]
它将返回一个UIRemoteNotificationType,您可以使用它来确定可用的内容.
UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
Run Code Online (Sandbox Code Playgroud)
现在,状态可以看作是一个int使用NSLog(@"status = ", status);,我们可以确切地确定是什么.但要做到这一点,我们需要了解UIRemoteNotificationType.
typedef enum {
UIRemoteNotificationTypeNone = 0,
UIRemoteNotificationTypeBadge = 1 << 0,
UIRemoteNotificationTypeSound = 1 << 1,
UIRemoteNotificationTypeAlert = 1 << 2,
UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3
} UIRemoteNotificationType;
Run Code Online (Sandbox Code Playgroud)
没有详细说明,你基本上需要摆脱这种认识的是......
假设您想知道徽章/声音/警报是否全部开启.UIRemoteNotificationType(如果你正在玩的状态)应该是7.
现在,让我们倒退吧.让我们说status == 5.只有一种设置配置可以为我们提供此值,即徽章和警报开启(徽章添加1,警报添加4,总数为5)并且声音关闭.
怎么status == 6办?同样,只有一种设置配置会返回此数字,即警报和声音都打开,而徽章则关闭.
使用IF语句,我们可以做类似的事情
If (status == 5)
{
NSLog(@"User has sound alerts disabled");
[self fireThatSpecialMethod];
}
Run Code Online (Sandbox Code Playgroud)
运行设置的代码块,或者在禁用声音时触发特定方法,但其他所有内容都已启用.无论如何,希望这个回复对人们有所帮助!
| 归档时间: |
|
| 查看次数: |
1775 次 |
| 最近记录: |