日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS 来电阻止和身份识别

發布時間:2023/12/16 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS 来电阻止和身份识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

年前各種項目驗收,總結,所以沒時間更新博客。年初,剛剛靜下來,這次文章,讓我們討論一下,iOS10新特性,來電識別和來電阻止

iOS 10中引入了許多新特性,其中 CallKit是一個非常重要的 API,The CallKit framework provides programmatic access to VoIP functionality, as well as call blocking and identification. 這意味著現在可以通過 Call Directory Extension 來實現電話識別和黑名單功能了。本文簡單闡述了如果實現簡單的來電識別和黑名單功能。
Extension一直很輕量,單一的,這次的 Call Directory Extension 也不出例外,出奇的簡單。下面我們逐步完成今天的任務

Step1、 創建Call Directory Extension

在對應項目中的file->new->target,選擇Application Extension中的Call Directory Extension,如圖:

輸入Extension項目名稱后,創建成功后會彈出這樣的提示框:點擊激活,直接進入到Extension項目。

Step2、 來電識別和來電阻止

1、項目創建成功后,在項目目錄文件中,生成了Info.plist、CallDirectoryHandler.h、CallDirectoryHandler.m三個文件。我們需要關注的是CallDirectoryHandler.m。
2、打開CallDirectoryHandler.m,里面自動生成了四個方法

- (void)beginRequestWithExtensionContext:(CXCallDirectoryExtensionContext *)context - (BOOL)addBlockingPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context - (BOOL)addIdentificationPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context - (void)requestFailedForExtensionContext:(CXCallDirectoryExtensionContext *)extensionContext withError:(NSError *)error

其中簡單的來電識別和來電阻止我們只要補全addIdentificationPhoneNumbersToContext和addBlockingPhoneNumbersToContext方法,在里面添加來電識別數據和黑名單數據就可以了。
3、來電識別

- (BOOL)addIdentificationPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context {- CXCallDirectoryPhoneNumber phoneNumbers[] = {+8613533533110,+8613726735411,+86158140043377};NSArray<NSString *> *labels = @[ @"Dear",@"陳老濕",@"乾坤"];NSUInteger count = (sizeof(phoneNumbers) / sizeof(CXCallDirectoryPhoneNumber));for (NSUInteger i = 0; i < count; i += 1) {CXCallDirectoryPhoneNumber phoneNumber = phoneNumbers[i];NSString *label = labels[i];[context addIdentificationEntryWithNextSequentialPhoneNumber:phoneNumber label:label];}return YES; }

注意點:1、電話號碼前要加區號:+86;2、電話號碼需要升序排列

4、來電阻止

- (BOOL)addBlockingPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context {CXCallDirectoryPhoneNumber phoneNumbers[] = {13726735412,18005555555 };NSUInteger count = (sizeof(phoneNumbers) / sizeof(CXCallDirectoryPhoneNumber));for (NSUInteger index = 0; index < count; index += 1) {CXCallDirectoryPhoneNumber phoneNumber = phoneNumbers[index];[context addBlockingEntryWithNextSequentialPhoneNumber:phoneNumber];}return YES; }

注意點:1、電話號碼需要升序排列

上面簡單介紹來電識別和來電阻止,現在我們安裝app到手機,必須是64位的設備。然后進入設備的設置 —> 電話 —> 來電阻止和身份識別,開啟我們的 App即可。

到此為止,我們簡單介紹如何簡單實現來電阻止和身份識別,利用Call Directory Extension很簡單實現該功能,重點是如何編輯這個黑名單列表。列表數據項可能很多,并且數據可能是實時更新添加的,那應該怎么做才更好呢?這個需要大家的思考~~

利用業余時間看了官方文檔,簡單介紹一下,如有理解錯誤,望大家指出

總結

以上是生活随笔為你收集整理的iOS 来电阻止和身份识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。