用于WhatsApp消息页面的Swift iOS -url无法打开或无法打开消息

时间:2019-07-28 13:50:43

标签: ios swift wkwebview uiapplication

userA将他们的电话号码上传到我的应用程序,并将其保存到数据库。在他们的个人资料页面上,有一个带whatsapp链接的按钮。

userB按下该按钮,并希望进入用户A的whatsapp页面,以便他们可以通过UIApplication.shared.open(url)WKWebView向userA发送消息

无论发生什么情况,我都会进入消息页面,但始终会从下面的代码的不同组合中得到这些错误

enter image description here

enter image description here

enter image description here

当我获得此页面时,直到我按下消息按钮才有错误

enter image description here

  

whatsapp:// send?phone = 12345 2019-07-28 09:25:38.200608-0400   myApp [87018:1555440] [ProcessSwapping] 0x1330bd160-   ProvisionalPageProxy :: didFailProvisionalLoadForFrame:pageID = 2   frameID = 1,navigationID = 16 https://www.whatsapp.com/download/   http://itunes.apple.com/us/app/whatsapp-messenger/idXXXXXXX?mt=8   itms-appss://apps.apple.com/us/app/whatsapp-messenger/idXXXXXXX   2019-07-28 09:25:39.502405-0400 myApp [87018:1555440] [ProcessSwapping]   0x1330bd2c0-ProvisionalPageProxy :: didFailProvisionalLoadForFrame:   pageID = 2,frameID = 1,navigationID = 17

我将此添加到了info.plist

<key>LSApplicationQueriesSchemes</key>
 <array>
    <string>whatsapp</string>
 </array>

我尝试了以下几种不同的组合:

let str = "https://api.whatsapp.com/send?phone=12125551515"

let str = "https://api.whatsapp.com/send?phone=+12125551212"

let str = "whatsapp://send?phone=121255512128&abid=12354&text=Hello"

let str = "whatsapp://send?phone=+121255512128&abid=12354&text=Hello"

let str = "https://api.whatsapp.com/send?phone=12125551212&text=Invitation"

let str = "https://api.whatsapp.com/send?phone=+12125551212&text=Invitation"

let str = "https://wa.me/12125551212"

let str = "https://wa.me/+12125551212"

//  I also tried  CharacterSet.urlQueryAllowed.insert("?&")
guard let urlString = str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else { return }

guard let url = URL(string: urlString) else { return } // I also tried this without the .addingPercentEncoding...
DispatchQueue.main.async {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

我尝试了这些常见问题解答

https://faq.whatsapp.com/en/android/26000030/

Open Whatsapp on a particular number in swift

Share link using whatsapp

https://help.instapage.com/hc/en-us/articles/360013414531-Integrating-with-WhatsApp

https://faq.whatsapp.com/en/iphone/23559013

how to integrate whatsapp in ios

我也尝试使用WKWebView,但发生相同的问题

let request = URLRequest(url: url)

webView.load(request)

我要去哪里错了?

0 个答案:

没有答案