我正在为我的 swift 应用程序使用 webview,我在我的网站上使用 WhatsApp 按钮分享,这在浏览器上运行良好,但是在 iPhone 应用程序上,当我点击 WhatsApp 分享按钮时,没有任何反应,我还创建了一个 android 应用程序使用相同的网站,我将此代码添加到我的应用程序中,以便 WhatsApp 共享工作..
if (url != null && url.startsWith("whatsapp://")) {
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
如何从我的应用程序打开 WhatsApp,我使用的是 Xcode 8 和 iOS 10
这是我的 WebView 应用:
最佳答案
您可以使用 URL 架构从您的应用程序打开 whatsapp。
class myViewController : UIViewController,UIWebViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string:"m.wahstatus.com/ws/punjabi-status/")
let request = NSURLRequest (url: url! as URL)
webView.frame = self.view.frame; webView.loadRequest(request as URLRequest)
webView.delegate = self
}
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if (request.URL.scheme == "whatsapp") {
let wurl = URL(string: "whatsapp://send?text=Hello%2C%20World!")!
if #available(iOS 10.0, *) {
UIApplication.shared.open(wurl, options: [:], completionHandler: nil)
} else { UIApplication.shared.openURL(wurl)
}
return false
}
return true
}
引用号https://www.whatsapp.com/faq/en/iphone/23559013用于发送媒体类型和其他用途。
关于ios - 从 webview Controller xcode 打开 Whatsapp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39832290/