0

I want to handle files in my iOS App. My app should create a file with a custom suffix (e.g. file.mysuff) and save it to the device so I'll be able to copy it using iTunes File Sharing. Then I want to be able to attach that file to a new mail. When the receiver opens the document, mail should launch my app and handle that file.

Are there good tutorials on that topic? I'm still quite new to cocoa / cocoa touch so it should be easy to my. Is maybe a wrapper out there that I could implement so I just have to code something like

[self [saveMyFile path:[NSURL] contents:[NSString]]]??

Thanks for help! Greets, J.

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107

1 Answers1

2

This is one example of how you can save the file to documents on the iPhone to use later. This stores a dictionary from a list, changes a value and then writes the updates dictionary back to the file specified. Let me know if this is what you were looking for.

//user document directory and instantiate dictionary
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    NSString *plistFilePathInDocumentsDirectory = [documentsDirectoryPath stringByAppendingPathComponent:@"YourFile"];
    NSMutableDictionary *yourList= [[NSMutableDictionary alloc] initWithContentsOfFile:plistFilePathInDocumentsDirectory];

//save the new information to the plist in the user documents directory
    [yourList setObject:someObject forKey:someKey];
    [yourList writeToFile:plistFilePathInDocumentsDirectory atomically:YES];
Kinetic Stack
  • 788
  • 12
  • 33
  • I don't really know, if this is what I'm looking for. I won't use plist files. I also want a custom file format. Something like a plain textfile with my own suffix. And when the user klicks on a file of that type (e.g. in Mail), it should launch my app. Where exactly is that Path? – Julian F. Weinert Dec 24 '11 at 19:36
  • I edited the code a bit and now it fits perfectly for my needs. Thank you a lot, great help! :)) – Julian F. Weinert Dec 25 '11 at 05:01