IOS - Can't open Whatsapp chat programatically, but can do it through HTML

前端 未结 2 1968
感情败类
感情败类 2021-01-14 17:45

I have a Web page with an anchor that has href=\"whatsapp:+(xxxxxxxxx)\", if i click on it on my iPhone (iOS 9), it opens WhatsApp in the chat view for that contact (i can s

2条回答
  •  悲哀的现实
    2021-01-14 18:30

    working fine with xcode 8.3.2 and swift 3

        let date = Date()
        let msg = "Hi my dear friends\(date)"
        let urlWhats = "whatsapp://send?phone=phoneNumber&abid=phoneNumber&text=hi"
        if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
            if let whatsappURL = NSURL(string: urlString) {
                if UIApplication.shared.canOpenURL(whatsappURL as URL) {
                    UIApplication.shared.openURL(whatsappURL as URL)
                } else {
                    print("please install watsapp")
                }
            }
        }
    

提交回复
热议问题