2017-07-14 67 views
1

如何斯威夫特发送消息,并链接到WhatsApp的3如何发送消息并链接到Swift 3中的WhatsApp?

我使用这个代码: Code

消息errore到控制台:

...failed for URL: "whatsapp://send?text=Check" - error: "This app is not allowed to query for scheme whatsapp"

谢谢

+1

[使用雨燕从您的应用程序发送消息的WhatsApp?](HTTPS的可能重复: //stackoverflow.com/questions/32042702/sending-message-to-whatsapp-from-your-app-using-swift) –

回答

4

你应该试试这个:

注意:您必须将WhatsApp应用程序安装到您的设备中。

斯威夫特3

var documentInteractionController: UIDocumentInteractionController = UIDocumentInteractionController() 

@IBAction func whatsappShareText(_ sender: AnyObject) 
{ 
    let originalString = "First Whatsapp Share" 
    let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed) 

    let url = URL(string: "whatsapp://send?text=\(escapedString!)") 

    if UIApplication.shared.canOpenURL(url! as URL) 
    { 
     UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil) 
    } 
} 

@IBAction func whatsappShareLink(_ sender: AnyObject) 
{ 
    let originalString = "https://www.google.co.in" 
    let escapedString = originalString.addingPercentEncoding(withAllowedCharacters:CharacterSet.urlQueryAllowed) 
    let url = URL(string: "whatsapp://send?text=\(escapedString!)") 

    if UIApplication.shared.canOpenURL(url! as URL) 
    { 
     UIApplication.shared.open(url! as URL, options: [:], completionHandler: nil) 
    } 
} 

在您的应用程序 “的info.plist” 添加该代码

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>whatsapp</string> 
</array> 
相关问题