0

I am working on callKit framework, I found that by the use of call directory extension, we can Identify the incoming phone number. My question how to implement a call directory extension in iOS app to identify incoming call detail. I am working in Objective C.

Let a number "+919876xxxxx" add in call directory extension using this method:

- (BOOL)addIdentificationPhoneNumbersToContext:(CXCallDirectoryExtensionContext *)context {
    // Numbers must be provided in numerically ascending order.
    CXCallDirectoryPhoneNumber phoneNumbers[] = {+919876xxxxx};

    NSArray<NSString *> *labels = @[ @"Telemarketer"];
    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;
}

And I on the call blocking and identification feature in the phone settings. When I call from this number it show the [App name] Caller ID: Telemarketer.

My question is how can I know this number in my application so that I show this number in table.

Thanks in Advance.

Saurabh Jain
  • 1,688
  • 14
  • 28
  • using extension , you want to create the extension – Anbu.Karthik Nov 28 '16 at 06:14
  • @Anbu.Karthik , Yes I want to create call directory extension which is new in iOS10 – Saurabh Jain Nov 28 '16 at 06:29
  • @Saurabh Jain Did you got solution? I have same issue, in my app call blocking functionality working fine but not able to identify call. If you have solved it, then please help. – Ved Dec 16 '16 at 13:04
  • @Saurabh Jain: I want to display label with name when call incoming/outgoing – Ved Dec 19 '16 at 07:13
  • @Saurabh Jain: Can you give me your mobile no i want to get some suggestions, if possible. – Ved Dec 19 '16 at 07:18
  • @Saurabh Jain I have created a demo app for blocking mobile no and identification, but I am not able to display labels on screen when incoming/outgoing call. As above your code. – Ved Dec 20 '16 at 04:54

2 Answers2

8

If this question is not how to write a call directory extension, but how to get the number of an incoming call, which I think is what the question is, then its not possible.

The call directory extension is not involved when there is an incoming call. All it does is register numbers that get stored in an internal SQL database that is private to the phone app. The call directory extension does NOT get run when there is an incoming call and therefore it and your app are not able to identify the number of an incoming call, this is the same as it has always been, it has not changed in iOS 10.

There is new functionality for call detection for Voip apps that was added in iOS 10, but if you are not a voip app you still cannot obtain the number of an incoming (or outgoing) call.

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
2

Firstly you need to enable your CallBlocker app in App Setting for that follow this -

Go to Settings->Phone->Call blocking & identification->Enable your App.

After that use addIdentificationEntry for adding entry

  private func addIdentificationPhoneNumbers(to context: CXCallDirectoryExtensionContext) throws {

        let phoneNumbers: [CXCallDirectoryPhoneNumber] = [ 18775555555, +919899999999 ]
        let labels = [ "Telemarketer", "Local business" ]

        for (phoneNumber, label) in zip(phoneNumbers, labels) {
            context.addIdentificationEntry(withNextSequentialPhoneNumber: phoneNumber, label: label)
        }
    }

Which is working fine in Xcode 8.x swift 3.x

Jack
  • 13,571
  • 6
  • 76
  • 98
  • How can i add dynamic phone numbers and label in above method – user2185354 Jun 13 '18 at 13:17
  • Dynamic number, are you indicating the unknown number calls, NO as per my knowledge that’s not possible, you must define number before recognise it. – Jack Jun 13 '18 at 14:04
  • 1
    You can fetch a list from a server, then iterate over it and call addIdentificationEntry. – Agreensh Oct 29 '18 at 12:54