2016-09-28 4 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]; 
} 

Warum meine einfache UILocalNotification nicht feuert?Meine einfache UILocalNotification wird nicht ausgelöst

+0

Drucken Sie den Wert von localNotification.fireDate kommt richtig oder nicht? – svrushal

+0

Sie müssen [Anwendung cancelAllLocalNotifications] anfordern; weil die Benachrichtigung der erste Wert ist. – Rock

Antwort

0

Haben Sie diesen Code in didFinishLaunchingWithOptions von AppDelegate

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

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

[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 

hinzugefügt Ich bin nicht sicher, dass Sie hinzugefügt oder nicht, aber wenn Sie dies verpasst haben, werden Sie nie lokale als auch Remote-Benachrichtigung erhalten.

+0

aber wenn ich presentLocalNotificationNow verwende, dann wird didRecieveLocalNotification-Delegat aufgerufen. –

+0

Ihre Methode wird aufgerufen, wenn die Benachrichtigung ausgelöst wird, aber sie wird unsichtbar sein. Um es sichtbar zu machen, müssen Sie den obigen Code schreiben. Versuchen Sie es einmal und lassen Sie es mich wissen. – Pushkraj

0

Sie müssen Notification-Einstellung für lokale und Remote-Benachrichtigung registrieren beide Bitte registrieren Sie die Benachrichtigungseinstellung zuerst.

Verwandte Themen