1

I want to take local assets(videos,photos) shared to Facebook,but Facebook's API require I must offer a url in local system gallery,How can I get it? thanks.

1 Answers1

0

first Didload() code like this

self.options.predicate = NSPredicate(format: "mediaSubtype == %ld", PHAssetMediaSubtype.videoHighFrameRate.rawValue)
            self.images = PHAsset.fetchAssets(with: PHAssetMediaType.video, options: nil)
            self.options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

            self.collectionView.reloadData()
            self.collectionView.dataSource = self
            self.collectionView.delegate = self

And in didselect() code like below

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let cell = collectionView.cellForItem(at: indexPath as IndexPath) as! custCollectionViewCell


        var videoURL: NSURL!

        var resourceArray: [AnyObject] = PHAssetResource.assetResources(for: self.images[indexPath.row] )
        var paths: [AnyObject] = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as [AnyObject]

        self.assetResource = resourceArray[0] as! PHAssetResource


        let filePath = paths[0].appending("/image.mov")
        videoURL = NSURL.init(fileURLWithPath: filePath )

        do
        {
            try    FileManager.default.removeItem(atPath: filePath )

        }
        catch
        {


        }
        PHAssetResourceManager.default().writeData(for: self.assetResource, toFile: videoURL as URL, options: nil, completionHandler: {_ in







        })
        let assets = AVAsset(url: NSURL(fileURLWithPath: filePath) as URL)
        let length = Float(assets.duration.value) / Float(assets.duration.timescale)
        if length != 0.0  {




            self.selectedImage = cell.photoImageView.image
            performSegue(withIdentifier: "show", sender: self)

        }

    }

Still you need any help feel free to ask me

JAck
  • 854
  • 9
  • 18