2016-09-28 60 views
0
-(void)setNoti { 
    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60]; 
    localNotification.alertBody = @"NOTI 1"; 
    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
    localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; 
    localNotification.repeatInterval = kCFCalendarUnitMinute; 
    NSDictionary *dict = @{@"nid":@"1"}; 
    localNotification.userInfo = dict; 
    [[UIApplication sharedApplication]scheduleLocalNotification:localNotification]; 
} 

爲什麼我的簡單UILocalNotification沒有觸發?我的簡單UILocalNotification沒有觸發

+0

打印localNotification.fireDate的值是否正確或不正確? – svrushal

+0

你需要[應用程序cancelAllLocalNotifications];因爲通知是存儲第一個值。 – Rock

回答

0

有你在didFinishLaunchingWithOptions添加該代碼的AppDelegate

UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge | 
      UIUserNotificationTypeSound | UIUserNotificationTypeAlert); 

UIUserNotificationSettings *mySettings = 
      [UIUserNotificationSettings settingsForTypes:types categories:nil]; 

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 

我不知道您添加或沒有,但如果你錯過了這一點,你將永遠不會得到本地以及遠程通知。

+0

但如果我使用presentLocalNotificationNow然後didRecieveLocalNotification委託被調用。 –

+0

當通知被觸發時,您的方法將被調用,但它將不可見。爲了使其可見,您必須編寫上面的代碼。 嘗試一次,讓我知道。 – Pushkraj

0

您必須註冊通知設置本地和遠程通知兩者請註冊通知設置首先。