第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

刪除特定的本地通知

刪除特定的本地通知

墨色風(fēng)雨 2019-07-30 11:07:56
刪除特定的本地通知我正在開發(fā)基于本地通知的iPhone鬧鐘應(yīng)用程序。刪除警報(bào)時,相關(guān)的本地通知應(yīng)取消。但是,如何確定要取消本地通知數(shù)組中的哪個對象呢?我知道[[UIApplication sharedApplication] cancelLocalNotification:notification]方法,但我怎么能得到這個'通知'取消它?
查看完整描述

3 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個贊

其他選擇:

首先,當(dāng)您創(chuàng)建本地通知時,可以將其存儲在用戶默認(rèn)值中以供將來使用,本地通知對象不能直接存儲在用戶默認(rèn)值中,此對象需要先轉(zhuǎn)換為NSData對象,然后NSData才能存入User defaults。以下是代碼:

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:localNotif];[[NSUserDefaults standardUserDefaults] setObject:data forKey:[NSString  stringWithFormat:@"%d",indexPath.row]];

存儲和計(jì)劃本地通知后,將來可能需要取消您之前創(chuàng)建的任何通知,因此您可以從用戶默認(rèn)值中檢索它。

NSData *data= [[NSUserDefaults standardUserDefaults] objectForKey:[NSString   stringWithFormat:@"%d",UniqueKey]];UILocalNotification *localNotif = [NSKeyedUnarchiver unarchiveObjectWithData:data];NSLog(@"Remove localnotification  are %@", localNotif);[[UIApplication sharedApplication] cancelLocalNotification:localNotif];[[NSUserDefaults standardUserDefaults] removeObjectForKey:[NSString stringWithFormat:@"%d",UniqueKey]];

希望這可以幫助


查看完整回答
反對 回復(fù) 2019-07-30
?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個贊

這就是我做的。

創(chuàng)建通知時,請執(zhí)行以下操作:

  // Create the notificationUILocalNotification *notification = [[UILocalNotification alloc]  init] ;notification.fireDate = alertDate;notification.timeZone = [NSTimeZone localTimeZone] ;notification.alertAction = NSLocalizedString(@"Start", @"Start");notification.alertBody = **notificationTitle**;notification.repeatInterval= NSMinuteCalendarUnit;notification.soundName=UILocalNotificationDefaultSoundName;notification.applicationIconBadgeNumber = 1;[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;

當(dāng)試圖刪除它時,請執(zhí)行以下操作:

 NSArray *arrayOfLocalNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications] ;for (UILocalNotification *localNotification in arrayOfLocalNotifications) {

    if ([localNotification.alertBody isEqualToString:savedTitle]) {
        NSLog(@"the notification this is canceld is %@", localNotification.alertBody);

        [[UIApplication sharedApplication] cancelLocalNotification:localNotification] ; // delete the notification from the system

    }}

此解決方案應(yīng)適用于多個通知,并且您不管理任何陣列或字典或用戶默認(rèn)值。您只需使用已保存到系統(tǒng)通知數(shù)據(jù)庫的數(shù)據(jù)即可。

希望這有助于未來的設(shè)計(jì)師和開發(fā)者


查看完整回答
反對 回復(fù) 2019-07-30
  • 3 回答
  • 0 關(guān)注
  • 705 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號