0

I want a phone number from a TextView to call the phone number when clicked:

Text View with phone number

The issue I am facing is that when clicking the link, the message app is opening instead. I tried the following code in iOS 12 and it worked as expected, but when I try on iOS 13 and 14, the message app opens instead of making a call using the "phone dialer app".

Tentative 1:

textView.Editable = false;
textView.DataDetectorTypes = UIDataDetectorType.PhoneNumber;

Tentative 2:

var phoneNumberLink = new Dictionary<string, string>(){ { "(855) 757-7328","tel:8557577328" } }
textView.Editable = false;
textView.SetAttributedTextForLinks("Please call us at (855) 757-7328", phoneNumberLink);
Marcelo
  • 157
  • 1
  • 7

2 Answers2

1

Actually, telpromt://0123456789 also did not work. I had to intercept the interaction with URL, the recommended ShouldInteractWithUrl did not work (ShouldInteractWithUrl was not triggered or called), so I had to use AllowUrlInteraction instead. The code looked something like this:

var description = new KiteEmbeddedLinkTextView()
{
    Editable = false,
    DataDetectorTypes = UIDataDetectorType.PhoneNumber,
    Text = message.MessageText
};
description.AllowUrlInteraction += AllowUrlInteraction;


private bool AllowUrlInteraction(UITextView textView, NSUrl url, NSRange characterRange, UITextItemInteraction interaction)
{
    UIApplication.SharedApplication.OpenUrl(url);
    return false;
}

For some reason none of the previous options worked for me, besides this one.

See: https://forums.xamarin.com/discussion/60345/uitextview-and-clickable-phonenumbers How to intercept click on link in UITextView?

Marcelo
  • 157
  • 1
  • 7
0

As mentioned https://forums.xamarin.com/discussion/33798/open-phone-dialer-from-app

The correct way to open the dialer is

   telprompt://0123456789

Make sure that there are no spaces.

FreakyAli
  • 10,567
  • 3
  • 19
  • 50
  • I see, I was actually just trying that after finding this discussion: https://stackoverflow.com/questions/58430053/tel-url-scheme-showing-as-action-sheet-in-ios-13 But honestly, it is annoying that "DataDetectorType" does not work for what I want =( I had to add a bunch of stuff to set up the SetAttributedTextForLinks. While DataDetectorType is only one simple line of code... Anyways... thank you very much! – Marcelo Oct 27 '20 at 04:40
  • Happy to help! :) – FreakyAli Oct 27 '20 at 04:51