我正在尝试在特定时间实现本地通知调用。这是我的代码。我在哪里做错了,请帮助我。
在 .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;
并在应用委托(delegate)文件中接收通知文件
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
// NSLog(@"%@", notification);
}
请让我知道我在哪里做错了。任何帮助将不胜感激。
最佳答案
你在哪里安排通知?
例如 -
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
本地通知在您安排之前不会出现。
关于ios - 如何在 iOS 中实现本地通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25421451/