2011-03-22 31 views

回答

11

嘗試調用該方法[[UIApplication sharedApplication] enabledRemoteNotificationTypes]

它會返回一個UIRemoteNotificationType您可以一起工作,以確定哪些是可用的。

UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

現在,狀態可以被看作是使用NSLog(@"status = ", status);一個int,這是我們能確定到底什麼是對。但要做到這一點,我們需要了解UIRemoteNotificationType。

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

沒有進入很多細節,你基本上需要從這個會心走開是...

  • 如果徽章上,加1
  • 如果聲音上,加2
  • 如果警報是上添加4
  • 如果報亭內容是可用的,加8(我不會擔心這個傢伙)

假設您想知道徽章/聲音/警報是否全部打開。 UIRemoteNotificationType(狀態如果你正在玩)應該是7.

現在,讓我們倒退。可以這樣說status == 5。只有一種設置配置可以給我們這個值,也就是徽章和警報開啓(徽章添加1,警報添加4,總數爲5)並且聲音關閉。

如果status == 6?同樣,只有一個設置配置會返回這個數字,也就是說,如果警報和聲音都處於打開狀態,而徽章關閉。

使用IF語句,我們可以做這樣的事情

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

要運行的代碼,一組塊,或火時禁用聲音的特定方法,但一切是。無論如何,希望這種迴應對人們有幫助!

+0

這真的幫助我 – 2012-12-28 13:32:49

0

需要注意的是,作爲的iOS 8你正在尋找,以確定是否遠程通知註冊的方法是這樣的:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 

您可以決定什麼種通知用戶當前已使用支持以下方法

[[UIApplication sharedApplication] currentUserNotificationSettings] 

這將返回一個UIUserNotificationSettings與對象所有你需要的信息。

文檔鏈接:

isRegisteredForRemoteNotifications

currentUserNotificationSettings

UIUserNotificationSettings

相關問題