2014-06-25 14 views
-1

我會寫一些代碼來詢問用戶在xcode 5上爲ios7.1啓用推送通知,這裏是我的代碼。單擊確定或不允許後,xcode推送通知

- (IBAction)funcTabToAllow:(id)sender 
{ 
    [self PushAllow]; 
} 

- (BOOL)PushAllow 
{ 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
    (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 

    return YES; 
} 

和任何工作正常,現在當用戶點擊我的按鈕,一個警告框顯示用於向用戶詢問是否OK不要讓,這裏是形象。

enter image description here

現在怎麼知道,如果用戶觸摸OK不允許?我想如果用戶點擊確定我會寫一些日誌。

感謝您的幫助。

+0

你看過'registerForRemoteNotificationTypes:'的文檔嗎? –

+0

@JesseRusak我會堅果我不知道如何自定義'UIRemoteNotificationTypeAlert' – vietnguyen09

回答

1

如果用戶允許您的應用程序接收推送通知,在這裏你會得到一個回調在你的AppDelegate:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 

實施該方法以接收回調。

失敗時,將其稱爲:

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 

the documentation for registerForRemoteNotificationTypes:得到這些從文本。文檔是你的朋友。