nsfilemanager

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

…衆ロ難τιáo~ 提交于 2019-12-07 06:47:42
问题 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]) {

containerURLForSecurityApplicationGroupIdentifier getting nil value

妖精的绣舞 提交于 2019-12-07 04:51:19
问题 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

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

左心房为你撑大大i 提交于 2019-12-07 03:02:20
问题 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

removeItemAtPath dosn't work on the device

偶尔善良 提交于 2019-12-06 21:15:34
I'v been struggling with this one for some time so any hint or suggestion are welcome. I'm trying to delete a file from a directory under "Documents". The problem is that the file is not delete on the device dow it is on the simulator. Just to add to the mystery, before the call to removeItemAtPath I check if the file exists with fileExistsAtPath, and even display the list of files under that folder. Attached the code for deletion: // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle

How do I get an NSArray of filenames of all files in a given directory in my app?

回眸只為那壹抹淺笑 提交于 2019-12-06 20:17:21
问题 What I want to do seems simple enough: Get an array of filenames in a given "directory" on my app. But the more I play around with NSFileManager and NSBundle I find myself getting more lost...I just want to get the filenames of the files organized in a specific directory in my iPhone Xcode project...For example: The directory in question is called "Images" (created using "Add > New Group" under the project icon in Xcode) and contains 10 .png images. It seems simple but I am getting nowhere. I

max length of file name

心已入冬 提交于 2019-12-06 18:06:41
问题 i am using the code below to save an image in the NSDocumentDirectory -(BOOL)saveImage:(UIImage *)image name:(NSString *)name{ NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *path = [NSString pathWithComponents:[NSArray arrayWithObjects:dir, name, nil]]; BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil]; if (!ok) { NSLog(@"Error creating file %@", path); } else {

Check if file exists at URL instead of path

荒凉一梦 提交于 2019-12-06 16:29:32
问题 How can I check if a file exists at a URL (instead of a path), in order to set a pre-populated default store into the iPhone Simulator: NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Food.sqlite"]; /* Set up the store. For the sake of illustration, provide a pre-populated default store. */ NSFileManager *fileManager = [NSFileManager defaultManager]; // If the expected store doesn't exist, copy the default store. if (![fileManager fileExistsAtPath

How to save image or video from UIPickerViewController to document directory?

♀尐吖头ヾ 提交于 2019-12-06 11:38:55
问题 Handle selected image or video: func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { print("ok") if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { //what to do to save that image } else { //how to get the video and save } } Save it to the document directory: let path = try! NSFileManager.defaultManager().URLForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomain: NSSearchPathDomainMask

Error deleting contents in directory - Domain=NSCocoaErrorDomain Code=4 | Domain=NSPOSIXErrorDomain Code=2 “No such file or directory”

∥☆過路亽.° 提交于 2019-12-06 11:29:42
How can I fix the following errors when running the code below? I already searched in SO but can't find anything for Swift 3. // Delete all files in given directory let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String let dataPath = NSURL(fileURLWithPath: path) if let enumerator = FileManager.default.enumerator(atPath: dataPath.path!) { while let fileName = enumerator.nextObject() as? String { do { try FileManager.default.removeItem(atPath: "\(dataPath)\(fileName)") } catch let e as NSError { print(e) } catch { print("error") } } } Log: Error

How to find file types in objective c

风格不统一 提交于 2019-12-06 11:03:24
问题 I have done a lot of research on this and haven't found anything useful. I want am making a simple program in objective c for personal use that opens files and gives information about them. The only problem i have encountered is that i cannot find the file of a file i am opening. Without simply looking at the extension, is there a way to find the full file format of a file in objective c? If possible, i would also like to be able to save that file in a different format. Information on this