【问题标题】:canOpenURL succeed but openURL fails, for tel as urlschemacanOpenURL 成功但 openURL 失败,对于 tel as urlschema
【发布时间】:2018-01-04 10:24:10
【问题描述】:

我的应用是这样的:

用户在一个文本字段中输入电话号码。应用程序保存它。然后它会显示带有“呼叫”按钮的电话号码详细屏幕。我调用canOpenURL 方法,如果成功,则保持我的通话按钮启用,否则保持禁用。

我正在创建格式如下的 URL:tel:phone number

现在,我的一位测试人员添加了电话号码 = '55'。现在,当我调用canOpenURL 时,它会成功,但是当我调用openURL 方法时,它没有显示电话号码的弹出窗口。

这个对于其他电话号码非常有效,即使是 2 位数的电话号码,例如 = 13,但对于某些特定的电话号码,例如 55,56,它会失败。

注意:根据我客户的要求,我不必对电话号码进行任何验证,例如它必须有 n 个字符左右。所以,请不要提供这样的答案。我需要 canOpenURL 成功而 openURL 失败的原因。

【问题讨论】:

    标签: ios swift url-scheme


    【解决方案1】:

    canOpenURL 函数只会检查架构是否有效,即是否安装了会处理 URL 的应用程序。 它并不是说 resource 是有效的,在你的情况下,number 是有效的。见https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl

    55 无效的问题是 - 如我所见 - 由 RFC 2806 中的 tel URLScheme 规范引起。 我复制了一些相关部分:

    telephone-url         = telephone-scheme ":"
                            telephone-subscriber
    telephone-scheme      = "tel"
    telephone-subscriber  = global-phone-number / local-phone-number
    global-phone-number   = "+" base-phone-number [isdn-subaddress]
                            [post-dial] *(area-specifier /
                            service-provider / future-extension)
    base-phone-number     = 1*phonedigit
    local-phone-number    = 1*(phonedigit / dtmf-digit /
                            pause-character) [isdn-subaddress]
                            [post-dial] area-specifier
                            *(area-specifier / service-provider /
                            future-extension)
    ...
    area-specifier        = ";" phone-context-tag "=" phone-context-ident
    

    当我阅读 EBFN 时,telephone-subscriper 总是以 +1 字符开头。

    进一步,在2.5.2 Phone numbers and their scope,RFC 说:

    If a <local-phone-number> is used, an
    <area-specifier> MUST be included as well.
    

    在我看来,这就是 tel:55 失败,但 tel:13 没问题的原因。

    【讨论】:

    • 根据您的说法,数字 25、29 等不应该工作,仅以 1 或 0 开头的数字应该只工作。虽然我尝试了不同的号码,但我发现:1.所有 3 位电话号码都可以使用,2.对于 1 位和 2 位电话号码,以 0,1 或 2 开头的电话号码有效,其他电话号码无效
    • 这很奇怪。在我解释 RFC 时,您可以使用 global 数字(以 + 字符开头)或始终需要 contextlocal 数字/i>,即 URI 末尾的 ;phone-context= 之类的东西。也许只有苹果知道他们做了什么……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多