NSDate now = [NSDate date];
//取得系統時間
NSCalendar calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
components = [calendar components:unitFlags fromDate:now];
NSInteger hour = [components hour];
NSInteger min = [components minute];
NSInteger sec = [components second];
NSInteger week = [components weekday];
NSLog(@"現在是%ld:%ld:%ld,周%ld",hour,min,sec,week);
UILocalNotification *localNotification = [[UILocalNotification alloc] init];//設定時區(跟隨手機的時區)localNotification.timeZone = [NSTimeZone defaultTimeZone];if (localNotification) { localNotification.alertBody = @"訊息推送訊息推送"; localNotification.alertAction = @"開啟"; //小表徵圖數字 localNotification.applicationIconBadgeNumber = 0; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *date = [formatter dateFromString:@"15:30:00"]; //通知發出的時間 localNotification.fireDate = date;}//迴圈通知的周期localNotification.repeatInterval = kCFCalendarUnitDay;//設定userinfo方便撤銷NSDictionary *info = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];localNotification.userInfo = info;//啟動任務[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; *//*for (UILocalNotification *obj in [UIApplication sharedApplication].scheduledLocalNotifications) { if ([obj.userInfo.allKeys containsObject:kLocalNotificationKey]) { [[UIApplication sharedApplication] cancelLocalNotification:obj]; }}// 設定一個按照固定時間的本地推送NSDate *now = [NSDate date];//取得系統時間NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];NSDateComponents *components = [[NSDateComponents alloc] init];NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;components = [calendar components:unitFlags fromDate:now];NSInteger hour = [components hour];NSInteger min = [components minute];NSInteger sec = [components second];NSInteger week = [components weekday];WDLog(@"現在是%ld:%ld:%ld,周%ld",hour,min,sec,week);UILocalNotification *localNotification = [[UILocalNotification alloc] init];//設定時區(跟隨手機的時區)localNotification.timeZone = [NSTimeZone defaultTimeZone];if (localNotification) { localNotification.alertBody = @"訊息推送訊息推送"; localNotification.alertAction = @"開啟"; //小表徵圖數字 localNotification.applicationIconBadgeNumber = 0; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSDate *date = [formatter dateFromString:@"15:30:00"]; //通知發出的時間 localNotification.fireDate = date;}//迴圈通知的周期localNotification.repeatInterval = kCFCalendarUnitDay;//設定userinfo方便撤銷NSDictionary *info = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];localNotification.userInfo = info;//啟動任務[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; *//*for (UILocalNotification *obj in [UIApplication sharedApplication].scheduledLocalNotifications) { if ([obj.userInfo.allKeys containsObject:kLocalNotificationKey]) { [[UIApplication sharedApplication] cancelLocalNotification:obj]; }}//直接取消全部本地通知//[[UIApplication sharedApplication] cancelAllLocalNotifications];