Using iOS 9 I'm attempting to use NSFileManager's
moveItemAtURL
:
do {
print(localURL) // http://localhost:3000/api/v1/activities
print(cacheFile) // file:///Users/kyledecot/Library/Developer/CoreSimulator/Devices/35C03988-D8F5-42E5-AB35-B99BE461EEAE/data/Containers/Data/Application/69593B3A-F764-4BC3-89AD-72B701BF85C8/Library/Caches/activities.json
try fileManager.moveItemAtURL(localURL, toURL: cacheFile)
} catch let error as NSError {
print(error)
}
When catching the error I'm getting:
Error Domain=NSCocoaErrorDomain Code=262 "The file “activities” couldn’t be opened because URL type http isn’t supported." UserInfo={NSURL=http://localhost:3000/api/v1/activities}
I've already added the appropriate values to my Info.plist
to ensure that ATS is happy (see screenshot). What's odd is that I am able to download the data from my local server using HTTP (via dataTaskWithRequest:
) but NSFileManager then complains about the same URL when trying to perform moveItemAtURL
.
There are two things to know here:
In iOS 9, by default, http://
is not supported. You must communicate securely (with https://
). You can turn off this feature in your Info.plist if you have to.
NSFileManager URLs must be paths to files on disk — that is, they must be file URLs. Yours is not; it's an http://
URL. If your goal is to download a file and then copy it somewhere, use NSURLSession's download task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With