2016-09-28 59 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

您必须注册通知设置本地和远程通知两者请注册通知设置首先。