Open Whatsapp on a particular number in swift

后端 未结 7 845
说谎
说谎 2020-12-30 01:50

I am trying to open a particular contact chat in whatsapp but not getting any solution. Please help i am totally stuck. I have tried this:

let whatsAppURL: N         


        
7条回答
  •  -上瘾入骨i
    2020-12-30 02:27

    1. Add attributes to the Info.plist source code file like this:

      LSApplicationQueriesSchemes
      
          whatsapp
      
      
    2. Use the following function on custom click in your app:

      func openWhatsapp(){
          let urlWhats = "https://wa.me/numberWithCountryCode"
          if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: CharacterSet.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 {
                          UIApplication.shared.openURL(whatsappURL)
                      }
                  } else {
                      Alert(withMessage: "You do not have WhatsApp installed! \nPlease install first.").show(andCloseAfter: 2.0)
                  }
              }
          }
      }
      

提交回复
热议问题