0

何かしたかった。通知は 11 時間と 12 時間に設定されています。11時ちょうどに設定された通知の登録を解除したいのですが、どうすればいいですか?

私のコード;

NSCalendar *greg = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
        NSDateComponents * component = [greg components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
        [component setYear:2013];
        [component setMonth:m];
        [component setDay:d];
        [component setHour:x];
        [component setMinute:y];

        UIDatePicker *dd = [[UIDatePicker alloc]init];
        [dd setDate:[greg dateFromComponents:component]];

        UILocalNotification * bildirim = [[UILocalNotification alloc]init];
        [bildirim setAlertBody:newtask.name];
        [bildirim setFireDate:dd.date];
        bildirim.soundName = UILocalNotificationDefaultSoundName;
        bildirim.alertAction = NSLocalizedString(@"Test", nil);
        //[bildirim setFireDate:[NSDate dateWithTimeIntervalSinceNow:0]];
        [bildirim setTimeZone:[NSTimeZone defaultTimeZone]];

        [[UIApplication sharedApplication] scheduleLocalNotification:bildirim];

コードを見つけました。残念ながら、このコードはすべての通知を削除しています。

[[UIApplication sharedApplication] cancelAllLocalNotifications];

私の悪い英語でごめんなさい。

4

1 に答える 1

0

作成中の 2 つのことはlocal notification、以下のように識別できるように、一意の ID を使用して作成します。

UILocalNotification * notification = [[UILocalNotification alloc]init];
notification.userInfo=[NSDictionary dictionaryWithObject:@"UNIQUE_ID" forKey:@"notifcation_id"];

次に、特定のものをキャンセルするには、次の手順が必要です

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

    if([[notificaiton.userInfo objectForKey:@"notifcation_id"] isEqualToString:UNIQUE_ID]){
        [[UIApplication sharedApplication] cancelLocalNotification:notificaiton];
        break;
    }
}

ではごきげんよう..

于 2013-04-20T18:24:49.983 に答える