2014-10-07 58 views
0

火災這裏是我的UILocalNotification代碼:uilocalnotification不是從應用內觸發,但是從模擬器

UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
localNotification.fireDate = aNewDate; 
localNotification.alertBody = alertBody; 
localNotification.soundName = UILocalNotificationDefaultSoundName; 
localNotification.applicationIconBadgeNumber = 1; 
localNotification.repeatInterval = NSDayCalendarUnit; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

它正確地從模擬火災,而不是從我的iPhone。有什麼建議麼?

參考,我檢查通知在設置和我的應用程序犯規出現在那裏

+0

你檢查設置,並沒有出現,意味着你沒有登記他們 – 2014-10-07 18:52:05

+0

希望把它作爲一個答案,對如何做一個解釋那?生病接受它 – Katushai 2014-10-07 19:00:24

回答

1

見:https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/index.html#//apple_ref/doc/uid/TP40006728-CH3-SW86

的iOS 8代碼:(如果針對iOS7你必須確保你沒有調用這些方法...)

scheduleLocalNotification:有一張紙條:

討論:在安排任何地方的通知之前,你必須調用 registerUserNotificationSettings:方法讓系統知道 您計劃向用戶顯示哪些警報類型(如果有)。

所以......

UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge; 

    UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 
相關問題