Iphone UILocalNotification或推送通知
在我的应用程序中,我有一系列朋友的生日,我需要在某人的生日即将到来时通知用户。阵列将有大约200个朋友的生日。在这种情况下,Iphone UILocalNotification或推送通知,iphone,ios,push-notification,uilocalnotification,Iphone,Ios,Push Notification,Uilocalnotification,在我的应用程序中,我有一系列朋友的生日,我需要在某人的生日即将到来时通知用户。阵列将有大约200个朋友的生日。在这种情况下, UILocalNotification将起作用或不起作用,正如苹果公司所说,设备上的每个应用程序都被限制在最快发出64个预定本地通知。如果是,我必须如何实现UILocalNotification 我不想推送通知。如有任何建议,将不胜感激 我正在按如下方式安排本地通知:- -(void) scheduleNotification{ AppDelegate *dele
UILocalNotification
将起作用或不起作用,正如苹果公司所说,设备上的每个应用程序都被限制在最快发出64个预定本地通知。
如果是,我必须如何实现UILocalNotification
我不想推送通知。如有任何建议,将不胜感激
我正在按如下方式安排本地通知:-
-(void) scheduleNotification{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[self.notifications removeAllObjects];
for (int i = 0; i< [delegate.viewController.contactList count] ; i++) {
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSString *name = [[delegate.viewController.contactList objectAtIndex:i]objectForKey:NAME_KEY];
NSString *birthday = [[delegate.viewController.contactList objectAtIndex:i]objectForKey:BIRTHDAY_KEY];
if (birthday) {
[formatter setDateFormat:@"MM/dd/yyyy"];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setTimeZone:[NSTimeZone systemTimeZone]];
NSDate *date = [formatter dateFromString:birthday];
if (date == nil) {
[formatter setDateFormat:@"MM/dd"];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setTimeZone:[NSTimeZone systemTimeZone]];
date = [formatter dateFromString:birthday];
}
NSCalendar *gregorianEnd = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *componentsEnd = [gregorianEnd components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:date];
componentsEnd.year = [[NSDate date] year];
date = [gregorianEnd dateFromComponents:componentsEnd];
self.alarmTime = [date dateByAddingTimeInterval:self.mTimeInterval];
localNotification.fireDate = _alarmTime;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = 1;
NSString *itemName = @"B'day Alert!!!";
NSString *msgName = [NSString stringWithFormat:@"Celebrate %@'s B'day",name];
NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:itemName,MessageKey, msgName,TitleKey, nil];
localNotification.userInfo = userDict;
localNotification.soundName = self.soundName;
localNotification.alertBody = [NSString stringWithFormat:@"Celebrate %@'s B'day",name];
[self.notifications addObject:localNotification];
}
}
}
}
我应该对上述功能进行哪些更改。您仍然可以使用UILocalNotification,只安排64个最近的生日。在应用程序中有活动时重新安排这些活动,以便更新最新的活动。我可以想象,64次通知会让用户有足够的时间再次启动应用程序。:-我在问题中添加了我的代码。我需要在代码中进行哪些更改。
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UILocalNotification* notification;
for (int i = 0; i< [self.settingVC.notifications count]; i++) {
notification = [self.settingVC.notifications objectAtIndex:i];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
NSString *itemName = [notification.userInfo objectForKey:TitleKey];
NSString *messageTitle = [notification.userInfo objectForKey:MessageKey];
[self _showAlert:itemName withTitle:messageTitle];
application.applicationIconBadgeNumber = notification.applicationIconBadgeNumber-1;
}