最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】iOS的swift中实现打电话

iOS crifan 2370浏览 0评论

需要在iOS中实现打电话功能。

参考:

ios – Make a phone call programmatically – Stack Overflow

telprompt://

不是官网指定的-》以后可能没用

最好加上:canOpenURL

objective c – How to call a phone number from ios app? – Stack Overflow

Getting the best behavior from phone call requests using ‘tel’ in an iOS app – RaizException – Raizlabs Developer BlogRaizException – Raizlabs Developer Blog

Apple URL Scheme Reference - Phone Links

iphone – Return to app behavior after phone call different in native code than UIWebView – Stack Overflow

jatraiz/RZTelpromptExample: RZTelpromptExample

www.ietf.org/rfc/rfc2806.txt

www.ietf.org/rfc/rfc2396.txt

【总结】

后来的后来,整理出对应函数了:

<code>
/***************************************************************************
 * Phone functions
 ***************************************************************************/

func doPhoneCall(_ curPhone:String) -&gt; Bool {
    var callOk = false
    
    if curPhone.notEmpty {
        let phoneTelStr = "tel://" + curPhone
        gLog.verbose("phoneTelStr=\(phoneTelStr)")
        //phoneTelStr=tel://13800001111
        if let phoneTelNsurl = URL(string: phoneTelStr) {
            gLog.verbose("phoneTelNsurl=\(phoneTelNsurl)")
            //phoneTelNsurl=tel://13800001111
            
            let application:UIApplication = UIApplication.shared
            if application.canOpenURL(phoneTelNsurl) {
                callOk = true
                
                UIApplication.shared.openURL(phoneTelNsurl)
            } else {
                //Note:
                //in iOS Simulator will fail:
                //canOpenURL: failed for URL: "tel://13800001111" - error: "This app is not allowed to query for scheme tel"
                print("application can not open: \(phoneTelNsurl)")
            }
        }
    } else {
        print("can not call for empty phone")
    }
    
    return callOk
}
</code>

详见:

https://github.com/crifan/crifanLib/blob/master/swift/CrifanLib/CrifanLib.swift

转载请注明:在路上 » 【已解决】iOS的swift中实现打电话

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. Thanks for sharing information I must say very informative blog post. Keep it up!!
    richardmsmith5年前 (2019-01-04)回复
91 queries in 0.173 seconds, using 22.08MB memory