Search code examples
iosswiftuiactivityviewcontroller

Share app link to by ActivityViewController iOS swift?


My app is not Live yet. I got the app ID from the App Store Connect. I want to share the app link on social media apps. I used the UIActivityViewController:

let string1 = "itms-apps://itunes.apple.com/app/idXXXXXXX"
let url = NSURL(string: string1)

let shareItems = [UIApplication.sharedApplication().openURL(url!)]
    
let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
self.presentViewController(activityViewController, animated: true, completion: nil)

Problem: It is not showing some social media apps like WhatsApp.

enter image description here


Solution

  • This is used to open the site, not to share the app:

    [UIApplication.sharedApplication().openURL(url!)]
    

    Do this instead:

    if let name = URL(string: "https://itunes.apple.com/us/app/myapp/idxxxxxxxx?ls=1&mt=8"), !name.absoluteString.isEmpty {
      let objectsToShare = [name]
      let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
      self.present(activityVC, animated: true, completion: nil)
    } else {
      // show alert for not available
    }
    

    for sample see this