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
  • 217
  • 1
  • 2
  • 11

3 Answers3

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
  • 217
  • 1
  • 2
  • 11
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
  • 13,349
  • 3
  • 23
  • 63
  • 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
0

I was going through the same problem: the QA person said she can't get the call action sheet to appear, but I couldn't get the message dialog to show.

It turns out that if you are not signed in to iCloud, the default behavior for tapping on links on a UITextView is to open the message app dialog.

Conclusion

Just sign in to iCloud on your phone, and the tel scheme URI will work like it should.

If there is a specific need to make sure that the call action sheet appears even when users are not signed in to iCloud (because most users will have signed in already) take matters into your own hands and handle it in UITextViewDelegate.textView(_:shouldInteractWith:in:interaction:).

funct7
  • 3,407
  • 2
  • 27
  • 33