Reputation: 3310
I am following the Xamarin guide to create an iPhone app that can block phone numbers or display caller id by creating a Call Directory Extension:
The code in Xamarin's documentation is not completely updated, but if you just create a Call Directory Extension in Xamarin Studio for OS X, you get some sample code to get you starting.
Below is the simplest possible code to block phone number 22334455:
[Register("CallDirectoryHandler")]
public class CallDirectoryHandler : CXCallDirectoryProvider, ICXCallDirectoryExtensionContextDelegate
{
protected CallDirectoryHandler(IntPtr handle) : base(handle) { }
public override void BeginRequestWithExtensionContext(NSExtensionContext context)
{
var cxContext = (CXCallDirectoryExtensionContext)context;
cxContext.Delegate = this;
cxContext.AddBlockingEntry(22334455);
//cxContext.AddIdentificationEntry(22334455, "Telemarketer");
cxContext.CompleteRequest(null);
}
public void RequestFailed(CXCallDirectoryExtensionContext extensionContext, NSError error) { }
}
From the sample code it seems it should be just as easy to display caller id for the same number, simply use the method AddIdentificationEntry instead of AddBlockingEntry, but I cannot get it to work.
What am I missing?
Upvotes: 1
Views: 1427
Reputation: 3310
The answer was frustratingly simple.
AddIdentificationEntry() requires the country code, AddBlockingEntry() does not.
When I added 47 (Norway's country code) to the beginning of the phone number, it worked. Here is the working code to display caller id for Norwegian phone number 22334455:
public override void BeginRequestWithExtensionContext(NSExtensionContext context)
{
var cxContext = (CXCallDirectoryExtensionContext)context;
cxContext.Delegate = this;
cxContext.AddIdentificationEntry(4722334455, "Telemarketer");
cxContext.CompleteRequest(null);
}
addBlockingEntry() works with both 22334455 and 4722334455 as input.
Upvotes: 3