use*_*604 4 objective-c nscalendar uilocalnotification ios7
我使用下面的代码来在特定时间安排本地通知.但通知是每分钟而不是一天后重复的.我是否错过了任何通知设置.我的时区是(亚洲/加尔各答(IST)偏移19800)并使用iPhone 4s.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;
NSDate *now = [NSDate date];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now];
[components setHour:12];
[components setMinute:00];
UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.fireDate = [calendar dateFromComponents:components];
[notification setAlertBody:@"U got notification!!!"];
// notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
Run Code Online (Sandbox Code Playgroud)
Svi*_*miv 14
你应该指定repeatInterval.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar] ;
NSDate *now = [NSDate date];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now];
[components setHour:12];
[components setMinute:00];
UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.fireDate = [calendar dateFromComponents:components];
notification.repeatInterval = NSDayCalendarUnit;
[notification setAlertBody:@"U got notification!!!"];
// notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3729 次 |
| 最近记录: |