ios - 从 webview Controller xcode 打开 Whatsapp

标签 ios xcode webview whatsapp

我正在为我的 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 应用:

enter image description here

最佳答案

您可以使用 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/

相关文章:

objective-c - iOS截图部分画面

ios - 在移动 Safari(iOS 模拟器)中单击按钮后触发 mouseUp

ios - 如何查看变量的值是否为Nil

iOS 6.1 兼容性

ios - 如何在右侧的 UIButton 上添加图像并且 contentMode 不适用于图像?

java - webview加载完成后如何显示?

c# - 脚本在 UWP 的 WebView 中不起作用

android - Android WebView 上的上下文菜单

jquery - “点击”不适用于 iOS cordova 上的某些元素

xcode - 在 XCode 中,有没有一种方法可以查找工作区中是否提到了某个 Assets ?