nsfilemanager

How to access created Directory? - NSCocoaErrorDomain Code=257

我的梦境 提交于 2020-01-30 12:55:16
问题 I am trying to create a new directory and put files into it. However, I'm getting Error Domain=NSCocoaErrorDomain Code=257 "The file “Offline” couldn’t be opened because you don’t have permission to view it." I am able to create this new directory and the file exists. let offlinePath = fileDirectory.appendingPathComponent("Offline") try? fileManager.createDirectory(at: offlinePath, withIntermediateDirectories: true, attributes: nil) files.forEach { file in if let localUrl = file.localUrl { do

Permission Denied when trying to create a directory in Application Support

本秂侑毒 提交于 2020-01-24 00:35:13
问题 I'm trying to create a directory inside the Application Support Directory, but it fails every single time. Here's the code: func getDownloadableContentPath() -> String { let paths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true) var directory = paths[0] directory = URL(fileURLWithPath: directory).appendingPathComponent("IAP").absoluteString let fileManager = FileManager.default if !fileManager.fileExists(atPath: directory) { do { try fileManager

PDF File reading Issue only on Offline mode swift

天涯浪子 提交于 2020-01-16 09:59:17
问题 I have successfully Implemented downloading mechanism for pdf files. Files are downloading and save to document directory of simulator. Issue is when I try to disconnect internet the files locally stored not accessible. In my application I have two modes Online and Offline. In Online mode I store data and its accessible at Offline mode. Only problem is getting with pdf files. How to access pdf files in offline mode? viewController Code: let fileType = (URL != nil) ? ".pdf" : ".png"

What exactly does *NSFileProtectionComplete* mean?

Deadly 提交于 2020-01-15 05:19:24
问题 I'm looking at the NSFileManager class reference and I'm a bit confused by what NSFileProtectionComplete means. This is what the class reference says: The file is stored in an encrypted format on disk and cannot be read from or written to while the device is locked or booting. Does this mean that the file is stored in encrypted format on disk always ... regardless of whether the device has a passcode (or similar security mechanism) set? 回答1: complete protection (NSFileProtectionComplete): The

iOS9 FileManager File permissions change

社会主义新天地 提交于 2020-01-15 01:48:17
问题 After switching my application to iOS9 I started to get errors that the files I was writing were not readable. Here is how I create the files let fileManager = NSFileManager.defaultManager() let directory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] let path = "\(directory)/file.txt" let attributes: [String:AnyObject] = [NSFilePosixPermissions: NSNumber(short: 666)] let success = fileManager.createFileAtPath(path, contents: nil, attributes: attributes)

Populating Collection View from Array in Document Directory

寵の児 提交于 2020-01-14 06:23:29
问题 This is a follow-up from this question. Thanks so much to @rmaddy and @LeoDabus for your help thus far! The Good : my addImage button gets me the correct image in collectionView the first time I pick an image. The Bad : the second time I select an image, it changes both cells to the 2nd image. By the third/fourth/etc times I try to addImage, the image is always the same across each cell no matter what image I choose (i.e. 1st try: image1, 2nd try: image 2, image 2, 3rd try: image 2, image 2,

NSFileSystemFreeSize

╄→尐↘猪︶ㄣ 提交于 2020-01-14 06:08:04
问题 I get a negaitve number from trying to use this function can anyone help. see code below NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:dbPath error:Error]; NSDictionary *fileSysAttributes = [fileManager fileSystemAttributesAtPath:dbPath]; NSNumber *FileSize = [fileAttributes objectForKey:NSFileSize]; NSNumber *FreeSpace = [fileSysAttributes objectForKey:NSFileSystemFreeSize]; NSLog(@"FileSystem = %@",fileSysAttributes); // gives good values NSLog(@"File Size = %d",

How to save images and recorded files in temp directory?

不羁岁月 提交于 2020-01-11 05:12:27
问题 I want to store pictures taken from camera and video recordings from my application in a separate folder in temporary directories for a while. And as the task is being completed, they shall be going to save into the database. How do I save pictures taken from camera & video recording files in a separate folder in temp directories? 回答1: You are looking for this to get tot he caches folder to store temporary files: NSString* path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,

Is there any function to retrieve the path associated with an NSFileSystemFileNumber?

安稳与你 提交于 2020-01-07 04:22:42
问题 I am writing a utility that walks a directory tree on Cocoa and tries to detect changes that have occurred since the directory was last synchronized with a back-up location. When I initially synchronize the files and folders I obtain the NSFileSystemFileNumber and store it in the database record for that file or folder: NSString *oldFilePath = /* ... */; NSError *error = nil; NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:oldFilePath error:&error]; /* set

Why saving and loading UIImages in documents folder doesn't work properly in iOS 8+?

依然范特西╮ 提交于 2020-01-07 03:41:34
问题 I've been trying to save and load UIImages in my app's Documents folder or preferably temp folder (so every time my app gets closed images will be deleted) but they aren't working correctly. I've tried three approaches but only the third approach works and i'm wondering what's the right way to do it? I highly appreciate any help. //First Approach, to save and load later, Doesn't work. //Saving the image NSURL *documentsDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory