Home / IOS Development / ios – WhatsApp VS WhatsApp Business and SWIFT

ios – WhatsApp VS WhatsApp Business and SWIFT



We would really appreciate help on the following. Through our app, the user can start a WhatsApp message (what happens is that the WhatsApp client starts with the phone + text preloaded, so the user only needs to press the “send”

; button from the WhatsApp application).

We have an Android and an iOS app. In Android, we use the following code to choose between WhatsApp and WhatsApp Business.

  String url = "https://api.whatsapp.com/send?phone=" + phoneNumberToUse + "&text=" + 
  URLEncoder.encode(messageText, "UTF-8");
  if(useWhatsAppBusiness){
    intent.setPackage("com.whatsapp.w4b");
  } else {
    intent.setPackage("com.whatsapp");
  }
  URLEncoder.encode(messageText, "UTF-8");
  intent.setPackage("com.whatsapp");
  intent.setData(Uri.parse(url));

  if (intent.resolveActivity(packageManager) != null) {
    startActivity(intent);
  } else {
    Toast.makeText(this, "WhatsApp application not found", Toast.LENGTH_SHORT).show();
  }

We try to achieve the same functionality on Swift for iOS, but we found no way to programmatically define whether the operating system should start WhatsApp or WhatsApp Business. The code below always starts one or the other, depending on which one is installed. If both are installed, the WhatsApp application launches.

  let whatsApp = "https://wa.me/(phoneNumber)/?text=(shareableMessageText)"

  guard let url = URL(string: whatsApp) else {
      return
  }
  if #available(iOS 10.0, *) {
      UIApplication.shared.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
  } else {
      UIApplication.shared.openURL(url)
  }

So in simple words, is there any way to choose which WhatsApp application (WhatsApp or WhatsApp Business) to launch from our app?

Thanks


Source link