0

私のアプリには、友達の誕生日の配列があり、誰かの誕生日が近づいたらユーザーに通知する必要があります。Array には約 200 人の友人の誕生日があります。この場合、

UILocalNotificationAppleが言うように、うまくEach application on a device is limited to the soonest-firing 64 scheduled local notifications.いくかどうかはわかりません。

私は行きたくありません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 デリゲートを次のように実装しました。

- (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 デリゲートには次のようなものがあります。

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

上記の機能にどのような変更を加える必要がありますか。

4

1 に答える 1

2

UILocalNotification を引き続き使用して、直近の 64 の誕生日のみをスケジュールすることができます。最新のアクティビティが更新されるように、アプリでアクティビティがあるたびにこれらのスケジュールを変更します。64 回の通知により、ユーザーがアプリを再度起動するまでに十分な時間を確保できると思います。

于 2013-03-16T20:03:30.747 に答える