nsfilemanager

Getting bundle file references / paths at app launch

别说谁变了你拦得住时间么 提交于 2019-11-30 00:12:43
问题 Suppose I have an arbitrary set of files included in the Main App Bundle. I would like to fetch the file URLs for those at launch and store them somewhere. Is this possible using NSFileManager ? The documentation is unclear in that regard. Note: I only need the file URLs, I do not need to access the actual files. 回答1: You can get the URL of a file in the main bundle using NSString *path = [[NSBundle mainBundle] pathForResource:@"SomeFile" ofType:@"jpeg"]; NSURL *url = [NSURL fileURLWithPath

How to create directory using Swift code (NSFileManager)

空扰寡人 提交于 2019-11-29 23:34:17
I'm having some trouble with converting Objective-C code to create a directory for Swift. Objective-C: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder"]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; Swift 5.0 let paths =

How to use iCloud to store and sync app files

烈酒焚心 提交于 2019-11-29 19:37:42
I already have an iPhone App that stores data in a file in the local documents folder. Now I learnt about iCloud technologies and my first question was: is there a way to use iCloud as a directory when sometimes I check for new versions? I mean: can I avoid using UIDocument, file coordinators and file presenters? I want just to know if could treat iCloud like a special folder and only use NSFileManager to push and retrieve files. Last note: I don't use Core Data or any database, I only have a data file. Edit: I already read the official Apple iCloud documentation so don't link me to them. I

NSFileManager - Check file size?

拥有回忆 提交于 2019-11-29 17:06:02
问题 I am recording sound file in one of my apps. I am trying to figure out how to get the file size of the recorded file? I know how to get it and it's path, I just can not figure out how to get the file size. Thanks Shani 回答1: you can use : - (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error to get the file property dictionary and can fetch [dictObject valueForKey@"NSFileSize"]; 来源: https://stackoverflow.com/questions/8844044/nsfilemanager-check-file-size

NSURLSessionDownloadTask move temporary file

我怕爱的太早我们不能终老 提交于 2019-11-29 16:16:06
I'm trying to reach the file which I was downloading earlier by NSURLSession . It seems I can't read the location of the file, even though I'm doing it before delegate method ends (as the file is temporary). Still, I'm getting nil when trying to access the data under location returned from NSURLSession delegate and error 257. The code goes as following: - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location { NSError *movingError = nil; NSData *fileData = [NSData dataWithContentsOfFile:location.path options:0

Ignore .DS_Store and Icon files in a folder with Cocoa NSFIleManager

こ雲淡風輕ζ 提交于 2019-11-29 11:58:29
问题 I'm trying to remove specific files from a directory using NSFileManager. I would like to ignore the hidden .DS_Store and Icon files (the folder that I'm checking has to have a custom icon) that are in the directory, however I keep accidentally deleting them as well. Right now, I'm doing the following: NSFileManager *manager = [NSFileManager defaultManager]; NSArray *dirContents = [manager contentsOfDirectoryAtPath:[selectedFolder stringValue] error:nil]; for (int i = 0; i < [dirContents

Disable backup of documents folder and all its sub folders on icloud?

[亡魂溺海] 提交于 2019-11-29 11:32:15
I have an already running enterprise application which stores a lot of documents inside the documents folders. I wish to disable the iCloud backup of all these documents and folders inside the Documents folder. The problem is that the contents inside the folder keep on changing dynamically and the idea of adding kCFURLIsExcludedFromBackupKey for every files sounds a bit difficult, as there are multiple classes in my code which can write to the documents directory. Is there any way I can disable the upload of the entire documents folder and its subfolder. Perhaps the files are changing

Read/write file in Documents directory problem

做~自己de王妃 提交于 2019-11-29 11:04:59
I am trying to write a very basic text string to my documents directory and work from there to later save other files etc. I am currently stuck with it not writing anything into my Documents directory (In my viewDidLoad ) NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) NSString *documentsDirectory = [pathArray objectAtIndex:0]; NSString *textPath = [documentsDirectory stringByAppendingPathComponent:@"file1.txt"]; NSString *text = @"My cool text message"; [[NSFileManager defaultManager] createFileAtPath:textPath contents:nil attributes:nil];

iOS - Flag entire Document directory as do not backup

纵饮孤独 提交于 2019-11-29 03:07:15
问题 My application got rejected by Apple due to : 2.23: Apps must follow the iOS Data Storage Guidelines or they will be rejected so is it possible that flag entire Document directory as do no backup ? my application runs in iOS 6.1 and higher . I am familiar with this code , but I don't know hot to mark my Document directory with it - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]); NSError *error = nil; BOOL success =

How To Get Directory Size With Swift On OS X

落花浮王杯 提交于 2019-11-29 02:31:37
I am trying to get the size of a directory, as well as it's content on OS X using Swift. So far, I have only been able to get the size of the directory itself, with none of it's content. For most of my directories it generally shows a value of 6,148 bytes but it does varie. I have tried the directorySize() function from the file below but it returned 6,148 bytes as well. https://github.com/amosavian/ExtDownloader/blob/2f7dba2ec1edd07282725ff47080e5e7af7dabea/Utility.swift I tried the top 2 answers from this question, but was unsure what argument it needed passed Swift to the Objective-C