Call Directory Extension: Read phone numbers to identify/block from external source

bjarteaobjarteao NOMember ✭✭

I'm creating a Call Directory Extension based on this example from Xamarin: Xamarin Example Code

When I follow the example exactly, it works well enough, but in the example all the phone numbers added to the Call Directory are hardcoded. That is not really a viable option, so I'm trying to figure out how I can get the phone numbers from an sqlite database.

My extension always crashes when I try to read the phone numbers, even when the database only contains a few phone numbers. I know the extension can access the database, I also use it for logging events, and the extension can write to the database without any issues.

Has anyone had any luck getting the phone numbers to identify/block from an external source, like a database or a file?

Maybe I need to read the database async or something similar, so the operation is not on the main thread?

Tagged:

Best Answer

Answers

  • Hello,

    Very useful info! thx

    Did you found the way how to debug extension?
    How do you communicate app with extension?

  • bjarteaobjarteao NOMember ✭✭
    edited January 3

    Hi, Damian. I have not found any way to debug the extension, so I'm logging a lot. I created a separate project for shared code between the app and the extension, where I have a logger method that writes to a log file.

    Inside the app I have a log reader that displays this log.

    To let the app and the extension read and write to the same file, they need to be a part of the same app group.

    To actually run the extension (add phone numbers to the phone's call directory), you can either go into the phone's settings and disable the extension and enable it again, or you can call this code from your app:

    var callDirManager = CXCallDirectoryManager.SharedInstance;
    callDirManager.ReloadExtension("com.mycompany.myappname.myextension", error =>
    {
        if (error == null)
        {
            // Ran extension successfully
        } else {
            // Extension failed, log error.Code and error.Description
            // Here are the meaning of the error codes:     
            // https://developer.apple.com/reference/callkit/cxerrorcodecalldirectorymanagererror.code/
        }
    });
    
  • bjarteaobjarteao NOMember ✭✭

    Here is a blog post I wrote with a bit more detail about how to get around the memory restrictions when you want to block thousands of phone numbers:
    https://basementmedia.no/2017/01/03/how-to-create-an-ios-call-directory-extension-in-xamarin-for-blocking-thousands-of-phone-numbers/

  • Hi Bjarte

    Awesome!
    You saved me a lot of time:)
    I will try to use files but ios guys gave me another solution to use UserDefaults but I'm not familiar with this and your method seams to me easier and better in that case.

  • bjarteaobjarteao NOMember ✭✭

    I'm using UserDefaults for my app's settings, but read somewhere that it's not a suitable place to store big chunks of data.

    Also the whole point of using many, small files, is that each file doesn't take a lot of memory to open and read. I guess that you will get the same memory issues I had when using a database when you are using UserDefaults, but I might very possibly be wrong :-)

    Let me know how it works out!

  • 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). It seems to work well for most users. However 1 case in iphone 7 plus that we 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 us know. Thanks so much.

  • bjarteaobjarteao NOMember ✭✭

    Hi, Thinh!

    Thanks for your question.

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

    When you go into your phone’s settings and click 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!

Sign In or Register to comment.