简体   繁体   English

如何使用 swift 从我的 ios 应用程序通过 WhatsApp 向特定联系人发送消息?

[英]How can I send message to specific contact through WhatsApp from my ios app using swift?

        // 1
        let urlWhats = "https://wa.me/\(mobile)/?text=\(text)"
        // 2
        if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
          // 3
          if let whatsappURL = NSURL(string: urlString) {
            // 4
            if UIApplication.shared.canOpenURL(whatsappURL as URL) {
              // 5
              UIApplication.shared.open(whatsappURL as URL, options: [:], completionHandler: nil)
//                UIApplication.shared.\
            } else {
              // 6
              print("Cannot Open Whatsapp")
            }
          }
        }

I'm able to launch whatsapp from my app from the above mentioned code, it is composing prefix text to the contact I wish to send and I need to click the send button in whatsapp manually.我可以通过上述代码从我的应用程序启动 whatsapp,它正在为我希望发送的联系人编写前缀文本,我需要手动单击 whatsapp 中的发送按钮。 But I'm looking for a code which automatically sends whatsapp text to number from my app.但我正在寻找一个自动将whatsapp文本从我的应用程序发送到数字的代码。 Can anyone share your thoughts on this?任何人都可以分享您对此的想法吗?

You can only compose the message for a particular contact using the Deep Linking method that you have used for it.您只能使用已用于特定联系人的Deep Linking方法为特定联系人撰写消息。 For sending the message user has to click on the send button manually.要发送消息,用户必须手动单击发送按钮。 You could provide the user with an alert that says so.您可以向用户提供这样的警报。 But, it's not possible to do it for the user from your side.但是,从您这边为用户做这件事是不可能的。 If you were able to send a message on Whatsapp by writing code without the user's confirmation it would be a break of user's privacy.如果您能够在没有用户确认的情况下通过编写代码在 Whatsapp 上发送消息,那将是对用户隐私的破坏。 Don't you think?你不觉得吗?

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

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