Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 read file permission

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: NSDataReadingOptions.DataReadingUncached)

or

NSData(contentsOfFile: stringpath)

Actions:
I have removed the "file://" from the path and it now has a permissions issue.

Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_0048.JPG” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/var/mobile/Media/DCIM/100APPLE/IMG_0048.JPG, NSUnderlyingError=0x13f978f50 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

I have added the NSAllowArbitraryLoads and set it to true.
I have tried to look for the file myself using "NSSearchPathDirectory" however the paths do not match in any way

like image 460
Lawgrin Foul Avatar asked Nov 02 '15 12:11

Lawgrin Foul


1 Answers

I encountered this error because I was attempting to access multiple files in the same block. The fix that worked for me was changing the code structure such that each file url was obtained, then read from, before attempting to get the next file url.

like image 96
Dan G Avatar answered Oct 12 '22 23:10

Dan G