Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UILocalNotification或推送通知_Iphone_Ios_Push Notification_Uilocalnotification - Fatal编程技术网

Iphone UILocalNotification或推送通知

Iphone UILocalNotification或推送通知,iphone,ios,push-notification,uilocalnotification,Iphone,Ios,Push Notification,Uilocalnotification,在我的应用程序中,我有一系列朋友的生日,我需要在某人的生日即将到来时通知用户。阵列将有大约200个朋友的生日。在这种情况下, UILocalNotification将起作用或不起作用,正如苹果公司所说,设备上的每个应用程序都被限制在最快发出64个预定本地通知。如果是,我必须如何实现UILocalNotification 我不想推送通知。如有任何建议,将不胜感激 我正在按如下方式安排本地通知:- -(void) scheduleNotification{ AppDelegate *dele

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

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