Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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_Uilocalnotification - Fatal编程技术网

Iphone 更改面板上的UILocalNotification计数

Iphone 更改面板上的UILocalNotification计数,iphone,ios,uilocalnotification,Iphone,Ios,Uilocalnotification,我遇到了以下问题:当我以以下方式发送UILocalNotification时: UILocalNotification *alarm = [[UILocalNotification alloc] init]; if (alarm) { alarm.fireDate = [NSDate date]; alarm.timeZone = [NSTimeZone defaultTimeZone]; alarm.repeatInterval = 0; alarm.sound

我遇到了以下问题:当我以以下方式发送UILocalNotification时:

UILocalNotification *alarm = [[UILocalNotification alloc] init];
if (alarm) {
    alarm.fireDate = [NSDate date];
    alarm.timeZone = [NSTimeZone defaultTimeZone];
    alarm.repeatInterval = 0;
    alarm.soundName = UILocalNotificationDefaultSoundName;
    alarm.alertBody ="This is 1 message";

    if (object) {
        NSDictionary *infoDic = [NSDictionary dictionaryWithObject:object forKey:objectkey];
        alarm.userInfo = infoDic;

    }


    [[UIApplication sharedApplication] presentLocalNotificationNow:alarm];
您可以看到代码:当我发送两次通知时,您可以收到两次消息: “这是一条消息” “这是一条信息”
在手机面板上。我不想更改alarm.alertBody内容,但当我收到两次消息时,我可以合并这两个消息 “这是一条消息” “这是一条信息”作为面板上的“有两条信息”。如果我可以完成任务,如果可以,我可以使用什么api? 在android中,状态信息和面板信息是不同的,但我认为iOS只有一个警报体,状态和面板是相同的,对吗

编辑:我不知道为什么给我-2,我的问题很简单?还是别的?答案不是我需要的


编辑2:我描述我的需求。当用户收到来自15个人的不同的1条消息时,它会一条接一条地出现,因此我不能给它[NSString stringWithFormat:@“有%d条消息”,计数],我只给它“有1条消息”,但当用户打开面板时,我只显示“有15条消息”,可以看到14条“有1条消息”。答案1,给我答案是:在状态“有15条消息”下,但没有人给我这么多消息,人们只给我1条消息

您可以创建一个函数来安排通知。 为警报MSG创建一个数组,每次使用计数器+1添加新警报。 然后,您可以将本地通知安排在特定日期,因为您希望这样做会有所帮助:

- (void)scheduleNotification:(NSDate*)showDate withMsg:(NSString*)msg
{
Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {

        UILocalNotification *notif = [[cls alloc] init];
        //      notif.fireDate = [datePicker date];

        //setting the fire dat of the local notification
        notif.fireDate = showDate;//[NSDate dateWithTimeIntervalSinceNow:5];


        //setting the time zone
        notif.timeZone = [NSTimeZone defaultTimeZone];

        //setting the message to display
        //notif.alertBody = @"You are notified";
        notif.alertBody = msg;

        //default notification sound
        notif.soundName = UILocalNotificationDefaultSoundName;

        //displaying the badge number
        notif.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;

        //schedule a notification at its specified time with the help of the app delegate
        //        NSLog(@"Todays date:%@ Notification Date:%@",[NSDate date],showDate);

        // Displaying Button tittle
        notif.alertAction = @"Show me";

        //      //setting the values in dict of local notification  
        //      NSDictionary *userDict = [NSDictionary dictionaryWithObject:_serverMsg
        //                                                             forKey:kRemindMeNotificationDataKey];
        //      notif.userInfo = userDict;

        [[UIApplication sharedApplication] scheduleLocalNotification:notif];

    }

}

我想合并两条消息。当第一次收到“这是一条消息”时,在第二次收到“这是一条消息”时,也会显示“这是一条消息”,但当您打开面板时,只会看到“有两条消息”。您的方法仅更改接收消息,而不更改面板消息。这可能是因为您没有取消以前计划的通知。请尝试[[UIApplication sharedApplication]cancelAllLocalNotifications];请尝试在绑定所有消息时发送调用此函数,您可以使用可变字符串。如何获取以前的通知?我无法使用CancelAllLocalNotifications我希望在状态消息与面板不同时接收您可以使用数组取消一个通知,并使用循环或其他方法检查通知<代码>-(无效)取消本地通知:(UILocalNotification*)通知NS\u可用\u IOS(4\u 0)