繁体   English   中英

iOS/Swift - 有没有办法将我们的应用程序链接为 WhatsApp 消息?

[英]iOS/Swift - Is there a way we can link our app as a WhatsApp message?

我的应用程序在我的 iPhone 上运行,我可以从我的应用程序向我的 WhatsApp 发送一些数据。 我经历了以下做同样的事情:

使用 Swift 从您的应用程序向 WhatsApp 发送消息?

有没有办法创建一个 URL,如果安装了它,它会直接打开我们自己的应用程序? 有人可以建议我可以理解如何完成的任何地方吗?

这样的事情应该工作:

let originalString = "Some text you want to send"
let encodedString = originalString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
let url = NSURL(string: "whatsapp://send?text="+encodedString!)

if UIApplication.sharedApplication().canOpenURL(url!) {

    UIApplication.sharedApplication().open(url as URL, options: [:]) { (success) in
                if success {
                    print("WhatsApp accessed successfully")
                } else {
                    print("Error accessing WhatsApp")
                }
            }

} else {

    print("whatsapp not installed")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM