如何在iOS中实现本地通知?
我正在尝试在特定时间实现本地通知调用。这是我的密码。如果我做错了,请帮助我。如何在iOS中实现本地通知?,ios,localnotification,Ios,Localnotification,我正在尝试在特定时间实现本地通知调用。这是我的密码。如果我做错了,请帮助我。 在.m文件中 NSDateComponents* deltaComps = [[NSDateComponents alloc] init] ; [deltaComps setDay:1]; NSDate* tomorrow = [[NSCalendar currentCalendar] dateByAddingComponents:deltaComps toDate:[NSDate
在.m文件中
NSDateComponents* deltaComps = [[NSDateComponents alloc] init] ;
[deltaComps setDay:1];
NSDate* tomorrow = [[NSCalendar currentCalendar] dateByAddingComponents:deltaComps toDate:[NSDate date] options:0];
//
// NSDate *date = [NSDate date];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)
// fromDate:tomorrow];
NSDateComponents *temp = [[NSDateComponents alloc]init];
[temp setYear:2014];
[temp setMonth:8];
[temp setDay:21];
[temp setHour: 13];
[temp setMinute:38];
NSDate *fireTime = [calendar dateFromComponents:temp]; // December 31st 2013 9:00
// set up the notifier
UILocalNotification *localNotification = [[UILocalNotification alloc]init];
localNotification.fireDate = fireTime;
localNotification.timeZone = [NSTimeZone systemTimeZone];
localNotification.alertBody=@"Nishant";
localNotification.alertAction = NSLocalizedString(@"Show", nil);
localNotification.soundName = @"Gentle Rise.m4a";
localNotification.hasAction = YES;
并在应用程序代理文件中接收通知文件
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// NSLog(@"%@", notification);
}
请告诉我哪里做错了。任何帮助都将不胜感激。您在哪里安排通知 e、 g-
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
localNotification在您安排之前不会出现。您在哪里安排
UILocalNotification
?您需要通过[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification]来计划它代码>感谢您的帮助@rckoenes