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.
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];