【问题标题】:Open whatsapp on iOS with new phone number pre-filled使用预先填写的新电话号码在 iOS 上打开 whatsapp
【发布时间】:2015-09-21 00:33:43
【问题描述】:

我知道有一些与 whatsapp 通信的方案,例如:

NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];
}

但我找不到如何使用以前不存在的电话号码打开 whatsapp。

这是一个“联系我们”页面,如果我只能打开whatsapp而不能预先填写电话号码,那就没用了。我需要与whatsapp联系...

我想要做的事情存在吗?

【问题讨论】:

    标签: ios objective-c whatsapp


    【解决方案1】:

    预填电话号码和文字

       NSURL *whatsappURL = [NSURL URLWithString:@"https://api.whatsapp.com/send?phone=9530670491&text=hello"];
    if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
        [[UIApplication sharedApplication] openURL: whatsappURL];
    }
    

    点击这里查看Swift

    查看链接了解更多详情https://www.whatsapp.com/faq/en/general/26000030

    【讨论】:

    • 允许苹果从应用程序发送消息
    【解决方案2】:

    根据Whatsapp documentation,您实际上需要在您的通讯录中有联系人才能从 url 方案中打开讨论。
    所以对于你的问题

    我尝试做的事情存在吗?

    答案是:不。

    【讨论】:

    • 遗憾的是, abid 参数已经消失。有谁知道直接从另一个 iOS 应用程序打开联系人聊天的任何替代方法?
    • @DanielFernandes 你能找到任何解决方案吗? ,我找到了这个链接faq.whatsapp.com/en/general/26000030
    • @MikeAlter,感谢您提供的链接,但是我不再使用 Whatsapp 集成。 :)
    【解决方案3】:

    您可以在答案上方找到该 whatsapp API 的文档。根据我自己的试验添加更多观点:

    要与特定联系人直接沟通,您需要遵守该联系人。 ABID 是保存联系人时系统自动生成的参数。因此,如果您的联系人中没有保存号码,那么您将无法从您的应用程序中打开它。

    我使用了一种解决方法。当您的应用程序第一次在设备中加载时,您会将联系我们的号码保存到地址簿中。成功保存号码后,您将在退货中获得 ABID。您可以使用该 ABID 来调用与该联系人的消息传递。

    NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?abid=123&text=Hello%2C%20World!"];
    

    【讨论】:

    • "whatsapp://send" 方法对我来说工作不稳定。对于某些 iOS 和 WhatsApp 版本,它不起作用。我建议使用“wa.me”。它以相同的方式工作,打开 WhatsApp 应用程序。
    【解决方案4】:

    如果有人在寻找 Swift 版本

    static func triggerWhats(_ vc:UIViewController){
            let msg = "Hello! I have a question"
            let urlWhats = "whatsapp://send?phone=+6599999999&text=\(msg)"
            if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
                if let whatsappURL = NSURL(string: urlString) {
                    if UIApplication.shared.canOpenURL(whatsappURL as URL) {
                        _ = UIApplication.shared.open(whatsappURL as URL, options: [:], completionHandler: nil)
                    } else {
                        // Cannot open whatsapp
                        ViewUtil().popAlertView(vc, title: "WhatsApp Support", message: "Please WhatsApp us at +65999999 if you have any questions", option: "Ok")
                    }
                }
            }
        }
    

    【讨论】:

    • "whatsapp://send" 方法对我来说不稳定。对于某些 iOS 和 WhatsApp 版本,它不起作用。我建议使用“wa.me”。它以相同的方式工作,打开 WhatsApp 应用程序。
    【解决方案5】:

    Swift 3.0 打开什么应用程序。

    info.plist 文件中添加这一行

    <key>LSApplicationQueriesSchemes</key>
    <array>
           <string>whatsapp://</string>
    </array>
    
    func OpenWhatsApp(_ vc:UIViewController){
            let msg = "" // here pass your message 
            let urlWhats = "https://api.whatsapp.com/send?phone=(Mobileno)&text=\(msg)" // Mobile number that include country code and without + sign . 
            if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed){
                if let whatsappURL = URL(string: urlString) {
                    if UIApplication.shared.canOpenURL(whatsappURL) {
                        if #available(iOS 10.0, *) {
                            _ = UIApplication.shared.open(whatsappURL, options: [:], completionHandler: nil)
                        } else {
                            // Fallback on earlier versions
                            UIApplication.shared.canOpenURL(whatsappURL)
                        }
                    } else {
                        // Cannot open whatsapp
                        AppUtilities.sharedInstance.showAlert(title: "WhatsApp Support", msg: "Your device is not support whats app")
                    }
                }
            }
        }
    

    【讨论】:

    • 你为什么一直使用NSURL 然后一直转换到 URL?您可以将 URL 声明为 URL
    • @AndyIbanez 是的,我可以改变它等等
    • @HimanshuMoradiya 我有一个问题,无论是印度还是外国,我都必须在 whatsapp 中打开一个号码,然后我该怎么办
    • urlwhats 应用程序打开一个聊天,特别喜欢在什么应用程序中包含国家代码且不带 + 号的手机号码。已存在于whats app 数据库中。
    【解决方案6】:

    对于 Swift 3.0 或更高版本,这将打开一个号码的 whatsapp 聊天

    号码示例:“+918798766554”

    if let whatappURL = URL(string: "https://api.whatsapp.com/send?phone=\(number)&text=\(msg)"),
      UIApplication.shared.canOpenURL(whatappURL)
    {
      if #available(iOS 10.0, *) {
        UIApplication.shared.open(whatappURL, options: [:], completionHandler: nil)
      } else {
        UIApplication.shared.openURL(whatappURL)
      }
    }
    

    【讨论】:

      【解决方案7】:

      根据Whatsapp documentation

      对于 Swift 3.0 或更高版本,这将打开一个号码的 whatsapp 聊天

      数字示例:“+6599999999”

      UIApplication.shared.open(URL(string: "https://wa.me/+6599999999")!)
      

      【讨论】:

        猜你喜欢
        • 2020-03-02
        • 1970-01-01
        • 2017-03-24
        • 2021-05-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多