gpt4 book ai didi

iphone - UILocalNotification 或推送通知

转载 作者:行者123 更新时间:2023-11-28 22:37:43 25 4
gpt4 key购买 nike

在我的应用程序中,我有一组 friend 的生日,我需要在某人的生日快到时通知用户。阵列将有大约 200 个 friend 的生日。在这种情况下,

UILocalNotification 是否可行,正如 Apple 所说 设备上的每个应用程序仅限于最快触发 64 个计划的本地通知。 如果是,我如何实现 UILocalNotication。

我不想使用 PushNotification。 如有任何建议,我们将不胜感激。

我正在这样安排本地通知:-

-(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];
}
}
}
}

我已经将我的 applicationDidEnterBackground 委托(delegate)实现为:

- (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];
}

}

此外,在 didReceiveLocalNotification 委托(delegate)中我有这个:

 - (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;
}

我应该对上述功能进行哪些更改。

最佳答案

你仍然可以使用 UILocalNotification 并且只安排 64 个最接近的生日。只要应用程序中有事件,就可以重新安排这些事件,以便更新最新的事件。我想 64 条通知会让用户有足够的时间再次启动应用程序。

关于iphone - UILocalNotification 或推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15453942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com