nsfilemanager

replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error: broken in iOS 6?

Deadly 提交于 2019-12-06 10:11:53
I cannot get the NSFileManager method replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error: to work in iOS 6. Apps that call this method and worked fine on iOS 5 have major issues on iOS 6. The problem does not occur on devices running versions of iOS below 6.0. The problem does not occur if the app is launched in the iOS Simulator by Xcode. Otherwise the problem seems to be universal. Here is the test code I am trying to execute: NSError *error; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *documentsDirectory =

iOS Application Library directory <uid> always gets changed

邮差的信 提交于 2019-12-06 04:26:17
After reading Apple documentation , I used URLsForDirectory to obtain the Library destination within my app, and my objective is to download content from a hosted service & cache it in the Library folder, so that User cannot interact with the contents through iTunes. NSArray *docPaths= [[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]; NSLog(@"%@",[docPaths description]); NSString *docPath=[(NSURL *)[docPaths objectAtIndex:0] path]; docPath = [docPath stringByAppendingPathComponent:@"audios"]; Running & executing the code several times(various

How can I get the file creation date using URL resourceValues method in Swift 3?

落花浮王杯 提交于 2019-12-06 04:23:10
Thanks to a variety of helpful posts in this forum, I have some code that works for obtaining the Creation Date of a single user-selected NSURL. However, I cannot get the code to work for either a hard-coded NSURL, nor within a loop through an NSFileManager enumerator. I am not a professional programmer; I make apps that are tools for office. My ultimate goal is to simply sort an Array of NSURL objects based on Creation Date. The code I am using is below, which functions just fine as is, but if I try to use the commented line to evaluate a specific PDF file, I get the following error: I get

fileManager.createFileAtPath always fails

夙愿已清 提交于 2019-12-06 04:04:47
I try to call the fileManager.createFileAtPath -method, but it always fails. My variable success is always false . I looked at some similar posts here but nothing fits my needs exactly. Here is my code: pListPath = NSURL(fileURLWithPath: String(reportsPath)).URLByAppendingPathComponent("myReports.plist", isDirectory: false) let data: NSData = NSData() var isDir: ObjCBool = false if fileManager.fileExistsAtPath(String(pListPath), isDirectory: &isDir) { print("File already exists") } else { let success = fileManager.createFileAtPath(String(pListPath), contents: data, attributes: nil) print("Was

NSFileManager & NSFilePosixPermissions

≡放荡痞女 提交于 2019-12-06 00:34:13
问题 I want to use the octal permissions (used for chmod) for NSFilePosixPermissions. Here is what I did now: NSFileManager *manager = [NSFileManager defaultManager]; NSDictionary *attributes; [attributes setValue:[NSString stringWithFormat:@"%d", 0777] forKey:@"NSFilePosixPermissions"]; // chmod permissions 777 [manager setAttributes:attributes ofItemAtPath:@"/Users/lucky/Desktop/script" error:nil]; I get no error, but when I check the result with "ls -o" the permission are't -rwxrwxrwx. What's

Performance of deleting folder with lots of files on iOS

给你一囗甜甜゛ 提交于 2019-12-05 11:47:08
Say I've got a folder in my iOS app's data directory with several thousand small files in it. Deleting this folder (via [NSFileManager removeItemAtPath] ) takes a nontrivial amount of time. But on OS X, deleting a folder with the same contents is very fast. It seems to simply unlink the folder from the filesystem. So why does iOS take so long? What is the difference? Edit: On an iPad 3, deleting 3 folders with 5,000 to 9,000 files each takes about 35 seconds. On the simulator running on an older Retina MBP, it takes about 1.5 seconds. Harsh The hierarchical structure that you see is not "real"

containerURLForSecurityApplicationGroupIdentifier getting nil value

不问归期 提交于 2019-12-05 10:11:06
I am making two iPad app that communicate with one file and fetches all the data from one file. I search and find this "containerURLForSecurityApplicationGroupIdentifier" we can create group and store in that. I have write the code below. In entitlement file i write <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.application-groups</key> <array> <string>$(TeamIdentifierPrefix)com.xxx.catalogapp

Why do I get “Cocoa error 513” when write files to “/var/mydir/files” on an jailbroken iPhone?

为君一笑 提交于 2019-12-05 09:09:53
My app will write some files to file system and it is installed in /Application not in /var/mobile/Application, On my develop iPhone, every things goes right.But when distribute to others, They got "Cocoa error 513".The files are written at /var/mydir/files, What's that problem? Where is right place for me to write with full permission? Thank you. Code: NSString *dir = @"/var/mydir/docs/"; NSFileManager *fileManager = [NSFileManager defaultManager]; if(![fileManager fileExistsAtPath:dir]) { NSError *error = nil; BOOL createdDir = [fileManager createDirectoryAtPath:dir

NSCocoaErrorDomain Code=257 file couldn’t be opened because you don’t have permission to view it : FileManager attributesOfItem returns nil in iOS13

故事扮演 提交于 2019-12-05 06:26:52
FileManager returns permission error while trying to get the file size, in iOS 13 devices. do { let attr = try FileManager.default.attributesOfItem(atPath: my_file_path) //--> Getting nil fileSize = attr[FileAttributeKey.size] as! UInt64 } catch { print("Error: \(error)") } Error returned: Error Domain=NSCocoaErrorDomain Code=257 "The file “trim.1A9FFC19-EE2C-438A-BF3D-97E05A97EF9E.MOV” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/PluginKitPlugin/ADB8684E-12B5-451D-A20F-158B899BB3DD/tmp/trim.1A9FFC19-EE2C-438A-BF3D

What is the proper way to move a UIDocument to a new location on the file-system

喜你入骨 提交于 2019-12-05 00:25:09
问题 I have a document-based iOS application with a UIDocument subclass. I need to be able to move the file it represents on the file-system. I have considered moving it with an NSFileManager , but this would mess up the UIDocument 's fileURL property. Any ideas on how to solve this little conundrum? 回答1: You can rename a UIDocument by first closing it, and then in the completion handler, moving the file using NSFileManager. Once the file has been successfully moved, initialize a new instance of