HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了当通知超过64 时,如何在iOS中安排更多本地通知大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Schedule number of Local Notifications6个
我正在开发一个日历应用程序,其中包含多个事件(例如500个事件),其中包括birthdays.I我正在下载事件表单Web服务.我想在生日那天上午10点的特定时间给每个出生日期的用户提醒.我正在使用本地通知来安排警报但我被困住,因为iOS每个应用程序只允许64个通知,我有多个生日.一旦应用程序超过限制,我不知道如何安排更多通知.请建议我如何解决这个问题.下面是我安排通知代码
- (void)scheduleNotification:(NSMutableArray *)datesArray withmessage:(NSMutableArray *)messagesArray  NotificationID:(NSString *)notificationID
{

    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterNoStyle];
    [formatter settimestyle:NSDateFormatterShortStyle];


    NSDateFormatter *formatter1 = [[NSDateFormatter alloc]init];
    [formatter1 setDateStyle:NSDateFormatterMediumStyle];
    [formatter1 setDateFormat:@"dd/MM/yyyy"];

   // NSDate *@R_597_6674@ = [formatter dateFromString:@"06:10 PM"];
    NSDate *@R_597_6674@ = [formatter dateFromString:fireTime];

    for (int i = 0; i < [datesArray count]; i++)
    {
        NSDate *myDate = [formatter1 dateFromString:[datesArray objectATindex:i]];

        NSDateComponents *dateComponents = [calendar components:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:myDate];
        NSDateComponents *timeComponents = [calendar components:NSHourCalendarUnit|NSminuteCalendarUnit fromDate:@R_597_6674@];

        NSDateComponents * newComponents = [[NSDateComponents alloc]init];
        NSDateComponents *todayComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];

        int day = [dateComponents day];
        int month = [dateComponents month];

        [newCompoents setDay:[dateComponents day]];
        [newCompoents setMonth:[dateComponents month]];

        if (day >= [todayComponents day] && month >= [todayComponents month]) { 
            NSLog(@"day = %d,month = %d",day,month);
            [newComponents setYear:[todayComponents year]];
        } else {
            NSLog(@"%d,%d",month);
            [newComponents setYear:[todayComponents year]+1];
        }


        [newComponents setHour:[timeComponents hour]];
        [newComponents setminute:[timeComponents minute]];

        NSDate *combDate = [calendar dateFromComponents: newComponents];

        localNotif = [[UIlocalnotification alloc] init];
        if (localNotif == nil)
            return;
        localNotif.fireDate = combDate;
        localNotif.timeZone = [NSTimeZone defaultTimeZone];

        // Notification details

        NSString *message = [@"Wish" StringByAppendingFormat:@" %@%@",[messagesArray objectATindex:i],@" On His Birthday"];
        localNotif.alertBody = message;

        // Set the action button
        localNotif.alertAction = @"View";

        localNotif.soundName = UIlocalnotificationDefaultSoundName;
        localNotif.applicationIconBadgenumber = 1;

        // Specify custom data for the notification
        NSDictionary *infoDict = [NSDictionary DictionaryWithObject:notificationID forKey:notificationID];
        localNotif.userInfo = infoDict;

        // schedule the notification
        [[UIApplication sharedApplication] schedulelocalnotification:localNotif];
    }

}

如果我犯了任何错误,请纠正我,并建议一旦超过64限制,如何安排更多通知.

解决方法

我有一个类似的问题和一些可能对你有帮助的选项,尽管它们都有缺陷,这意味着无法保证正确的行为.

请记住,重叠的生日可能在这里很有用.如果两个人最终在同一天过生日,请取消并重新安排他们的相关信息.如果你没有通用消息,你可以找到重复发生的其他间隔.

显然,让用户按下通知以打开应用程序会有所帮助(也可能与您的广告收入有关).你可以为你的最后一个尝试一个好消息.

这很麻烦,但你可以使用geofencing(但可能不是远程通知),如下所述:Can push notifications be used to run code without notifying user?.如果添加使用它的功能,您甚至可以获得批准.

我也虑过传递一个自定义日历,但NSCalendar是免费的CFCalendarRef桥接,故事似乎是我没有运气试图深入研究(并至少获得批准).我很高兴被告知我错了.

大佬总结

以上是大佬教程为你收集整理的当通知超过64 时,如何在iOS中安排更多本地通知全部内容,希望文章能够帮你解决当通知超过64 时,如何在iOS中安排更多本地通知所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。