我正在创建一个应用程序,通过收集365英语“谚语”。在我的应用程序中,我想使用本地通知(每天我的应用程序的说法应通知用户)。我想使用本地通知,而不是推送通知。可以每天(365天)通知用户不同的说法。任何人都可以帮助我.....
答案 0 :(得分:1)
无法创建365种不同的本地通知。 根据{{3}}本地通知仅限于64个预定的本地通知。
但是,当用户启动您的应用时,您可以更新通知。 如果通知内容相同,您还可以在documentation
上安排发送通知答案 1 :(得分:0)
是的,你可以。只需创建365个字典的数组。字典键应该是id和说。
UILocalNotification *localNotif = [[UILocalNotification alloc]init];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *datePickerDate = [NSDate date];
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:datePickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:datePickerDate];
NSDateComponents *dateComps = [[NSDateComponents alloc]init];
[dateComps setYear:[dateComponents year]];
[dateComps setMonth:[dateComponents month]];
[dateComps setDay:[dateComponents day] + 1];
[dateComps setHour:[timeComponents hour] ];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:00];
NSDate *fireDate = [calendar dateFromComponents:dateComps];
//NSLog(@"%@",fireDate);
localNotif.fireDate = fireDate;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.alertAction = @"Alarm";
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"id", nil];
localNotif.alertBody = [saying with id 1];//you can use predicate here
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
在应用程序委托中,
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
int i = [[localNotif.userInfo objectForKey:@"id"] intValue] + 1;
localNotif.alertBody = [saying in index i ];
[localNotif.userInfo setValue:i forKey:@"id"];
}