Share video to Instagram feed from iOS

前端 未结 3 1611
無奈伤痛
無奈伤痛 2021-02-04 08:23

I\'ve been trying to create a sharing experience for our app where Instagram launches giving these two options:

Facebook has a pretty lean documentation about i

3条回答
  •  生来不讨喜
    2021-02-04 08:46

    Try this :-

    I am currently sharing my last saved video by this:-

        let fetchOptions = PHFetchOptions()
        fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
        let fetchResult = PHAsset.fetchAssets(with: .video, options: fetchOptions)
        if let lastAsset = fetchResult.firstObject {
            let localIdentifier = lastAsset.localIdentifier
            let u = "instagram://library?LocalIdentifier=" + localIdentifier
            let url = NSURL(string: u)!
            if UIApplication.shared.canOpenURL(url as URL) {
                UIApplication.shared.open(URL(string: u)!, options: [:], completionHandler: nil)
            } else {
    
                let urlStr = "https://itunes.apple.com/in/app/instagram/id389801252?mt=8"
                if #available(iOS 10.0, *) {
                    UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)
    
                } else {
                    UIApplication.shared.openURL(URL(string: urlStr)!)
                }
            }
    
        }
    

提交回复
热议问题