How to create an iOS call directory extension in Xamarin for blocking thousands of phone numbers

A call directory extension is used to block or identify phone numbers on an iPhone, phone numbers the user don’t have in their contact list

TL;DR: Because iOS app extensions have very limited resources, it is difficult to load many thousand phone numbers into the call directory without the extension crashing
. This is my attempt to get around this issue.

This post expands on Xamarin’s tutorial for how to create a call directory extension, which you probably should read first, here:
Xamarin: Implementing a Call Directory Extension

The end result of that tutorial is a call directory extension that can block or identify two hard coded phone numbers.

Based on Xamarin’s sample code, I have further made an accompanying app that saves some thousand phone numbers in text files. The app saves the phone numbers in files called phonenumbers.0.txt, phonenumbers.1.txt, etc., with a few hundred phone numbers in each file

It is really important that the phone numbers are in numerical order, smallest number first. You don’t want to do any sorting or filtering in the extension, do all that kind of memory intensive tasks in the app when you create the text files

Another important nugget of information, is that a phone number has to be saved including the country code

citrate, cialis The rational selection of therapy for patients is only.

. So American phone numbers always start with 1, and Norwegian phone numbers always start with 47

This is my modified method to add phone numbers from the text files to the phone’s identification directory:


  1. Nevermind .. got it 🙂

    Naive question .. can I send a local notification when it does the identification? or can I send any kind of trigger to container app?

      1. Can you please explain App Group creation required for sharing files between extension and the app?

      2. Hi, Pooran

        You ask how to create an app group. It is not straightforward, but it’s done in Apple’s developer portal. This is from Apple’s documentation: “To enable data sharing, use Xcode or the Developer portal to enable app groups for the containing app and its contained app extensions. Next, register the app group in the portal and specify the app group to use in the containing app.”

        The full documentation here:

      3. I want to get numbers from api, but I always get an error, do you have any sample about that way?

  2. Please help us. Call Directory Extension – Error Enabling Extension. Failed to request data
    Our app is using the caller id feature of Call Directory Extension(Xamarin Form like you shows). It seems to work well for most users. However 1 case in iphone 7 plus that i cannot enable the extension in Settings > Phone > Call Blocking & Identification. I gets the message “Error Enabling Extension. Failed to request data for appName. You may try enabling the extension again…”. What is a root cause of this error. Please let me know. Thanks so much.

    1. Hi, thingng!

      Thanks for your question.

      I think any exception inside your extension can cause this error.

      When you go into your phone’s settings and clicking Enabled (green) for your extension, you are immediately running the code in your extension. Any exceptions will cause the extension to crash, and the phone turns the setting back to Disabled (grey).

      Since you cannot directly attach a debugger to the code that is running inside the extension, you must instead log a lot. I log to a text file.

      If you have no idea where the code crashes, start by logging the first line of code, and then continue through your code, logging each step the extension performs until you reach the point where the extension crashes, and therefore does not log anymore.

      Hope that was helpful. I’m afraid debugging extensions is a bit difficult.

      Good luck!

  3. Ibrahim says:
    2017-11-27 at 07:26
    I want to get numbers from api, but I always get an error, do you have any sample about that way?

    I don’t think it’s possible to get the phone numbers from the Call Directory Extension, only put numbers in.

    1. I want to get phone numbers in the calldirectory extension from api and use this numbers in AddIentificationEntry method. Is it ‘one’ way to get numbers from .txt file?? Or is there any way for getting numbers?

  4. The right question is , How to get phone numbers dynamically for adding identification entry?

    1. Ok, then I understand your question.

      I used the method string[] System.IO.File.ReadAllLines(string path) to read the file, like in this example:

      var fileManager = new NSFileManager();
      var filePath = Path.Combine(fileManager.GetContainerUrl(“”).Path, “phonenumbers.txt”);
      var phonenumbers = File.ReadAllLines(filePath);

      I have not created my app in Xamarin Forms, but in Xamarin.iOS. So if System.IO is not supported, I don’t have any tips, I’m afraid.

  5. could i use to identify callers that are blocking the phone number dynamically? ie. for example a nuisance caller who is hiding their identity so i can just kill incoming call at that point?

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.