Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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
Ios 我可以不显示UILocalNotification吗?_Ios_Objective C_Notifications_Uilocalnotification - Fatal编程技术网

Ios 我可以不显示UILocalNotification吗?

Ios 我可以不显示UILocalNotification吗?,ios,objective-c,notifications,uilocalnotification,Ios,Objective C,Notifications,Uilocalnotification,我有一个客观的c应用程序。我以一定的时间间隔显示UILocalNotifications。但后来又添加了这个,我不想显示已确定的通知 例如,我向通知添加一个键和值,如果在didReceiveLocalNotification函数中接收的通知的键为2,我希望显示,但是如果通知的键为1,我不希望显示 这可能吗 我正在使用此代码尝试此操作,但始终显示所有通知: UILocalNotification *notification = [[UILocalNotification alloc] init];

我有一个客观的c应用程序。我以一定的时间间隔显示UILocalNotifications。但后来又添加了这个,我不想显示已确定的通知

例如,我向通知添加一个键和值,如果在didReceiveLocalNotification函数中接收的通知的键为2,我希望显示,但是如果通知的键为1,我不希望显示

这可能吗

我正在使用此代码尝试此操作,但始终显示所有通知:

UILocalNotification *notification = [[UILocalNotification alloc] init];
        //notification.fireDate = [[NSDate date] dateByAddingTimeInterval:1];
        notification.alertBody = @"Hello!";
        notification.soundName =  @"Alarm-Clock.caf";
        NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"key1", @"1", nil];
        notification.userInfo = infoDict;
        notification.repeatInterval = NSCalendarUnitMinute;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];


- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
if([[notification.userInfo valueForKey:@"1"] isEqual:@"key1"]){
            [[UIApplication sharedApplication] cancelLocalNotification:notification];
        }

您可能希望使用以下命令,但需要在触发UILocationNotification之前执行,而不是之后

for (UILocalNotification *localNotification in [[UIApplication sharedApplication] scheduledLocalNotifications]) {

    if ([[localNotification.userInfo valueForKey:@"1"] isEqual:@"key1"]) {

        [[UIApplication sharedApplication] cancelLocalNotification:localNotification];

    }

}
希望这有帮助


干杯。

在UILocationNotification被触发之前,您是什么意思?我可以将此调用到didReceiveLocalNotification中吗?因为我首先添加UILocalNotification,然后在一分钟后它将显示我不想显示。希望您的回答很清楚,谢谢您的回答。是的,您可以打电话到
direceivelocalnotification
,因为下一个通知没有发出,它将被取消。