記近期處理iOS10的通知時(shí)遇到的一個(gè)坑:
iOS10的取消未展示通知方法removePendingNotificationRequestsWithIdentifiers:和removeAllPendingNotificationRequests方法是異步執(zhí)行的,導(dǎo)致不能取消,而引起用戶已取消的通知仍會(huì)提醒。。。

在解決該問題時(shí)想到了“調(diào)度組”,將該異步執(zhí)行的方法放入調(diào)度組中,使用調(diào)度組進(jìn)行監(jiān)聽,同時(shí)暫時(shí)阻塞處理該方法的隊(duì)列,等處理完成后再在該隊(duì)列進(jìn)行后續(xù)通知用戶或發(fā)出刷新UI通知操作~
代碼:
dispatch_queue_tqueue = dispatch_get_global_queue(0,0);
dispatch_group_tgroup = dispatch_group_create();
dispatch_group_enter(group);
dispatch_async(queue, ^{
[center removePendingNotificationRequestsWithIdentifiers:@[keys]];
dispatch_group_leave(group);
});
dispatch_group_notify(group, queue, ^{
// 開始調(diào)度的通知
});
// 用戶提醒 ?正在處理中
// DISPATCH_TIME_FOREVER表示一直等待該任務(wù),直到執(zhí)行結(jié)束該隊(duì)列的阻塞才會(huì)被取消
dispatch_group_wait(group,DISPATCH_TIME_FOREVER);
因?yàn)樘幚砣∠牟僮飨到y(tǒng)執(zhí)行速度比較快,對于主隊(duì)列的阻塞并不會(huì)太長所以采取了這種方式,有大神會(huì)有好的方法還請不吝賜教~