iOS 9 read file permission

前端 未结 4 1109
谎友^
谎友^ 2020-12-20 15:16

In iOS 9+ I get a nil on any attempt to read from file. The file in this case is a image file path.
using

NSData(contentsOfFile: stringpath, options: NSD         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 16:08

    In your Application, you don't have permission to access the file of /var/mobile/Media/DCIM/100APPLE/IMG_0048.JPG, because of Sandboxing.

    So, whatever you do, you can't initialize NSData or UIImage with the file path. But you can access the file of /var/mobile/Media/DCIM/100APPLE/xxx.mov with AVURLAsset. In my application, I extracted the data rather than URL from gallery by Photos kit and initialized UIImage with the data.

    PHImageManager.default().requestImageData(
        for: assetObject!, options: options,
        resultHandler: {
            data, _, _, _ in
            if data != nil {
                self.assetUrl = movieMaker.createMovieFrom(imageData: data!, duration: Int(CXPreparetValue.imageDuration))
            }
    })
    

    it works for me! If you have other opinions, please tell me.

提交回复
热议问题