【问题标题】:iOS phone link opening message app instead of calling the numberiOS电话链接打开消息应用程序而不是拨打号码
【发布时间】:2020-10-27 03:42:26
【问题描述】:

我希望 TextView 中的电话号码在点击时拨打电话号码:

我面临的问题是单击链接时,消息应用程序正在打开。我在 iOS 12 中尝试了以下代码,它按预期工作,但是当我在 iOS 13 和 14 上尝试时,消息应用程序打开而不是使用“电话拨号器应用程序”拨打电话。

暂定1:

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

暂定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);

【问题讨论】:

标签: c# ios xamarin


【解决方案1】:

其实telpromt://0123456789也没有用。我不得不拦截与 URL 的交互,推荐的ShouldInteractWithUrl 不起作用(ShouldInteractWithUrl 没有被触发或调用),所以我不得不改用AllowUrlInteraction。代码看起来像这样:

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;
}

由于某种原因,除了这个之外,以前的选项都不适合我。

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

【讨论】:

    【解决方案2】:

    如上所述https://forums.xamarin.com/discussion/33798/open-phone-dialer-from-app

    拨号器的正确打开方式是

       telprompt://0123456789
    

    确保没有空格。

    【讨论】:

    • 我明白了,我实际上只是在找到此讨论后尝试这样做:stackoverflow.com/questions/58430053/… 但老实说,“DataDetectorType”不适用于我想要的东西,这很烦人=(我不得不添加一堆设置 SetAttributedTextForLinks 的东西。虽然 DataDetectorType 只是一个简单的代码行......无论如何......非常感谢!
    • 乐于助人! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    相关资源
    最近更新 更多