Search code examples
objective-cipadplistitunesfile-sharing

Update plist file in File Sharing folder - I really need advice


I need to open a plist file located in the File Sharing folder, to add two pieces of user info to each time the app is launched; as in a new Name and Email of the user (both are of type NSString and the plist file is Dictionary).

It then needs to save the file back to the File Sharing folder again, so that the new updated plist file can be removed at a later time via iTunes.

If anyone could help it would be greatly appreciated


Solution

  • Storing a plist in the Documents directory is possible. You will be able to load the plist into an NSMutableDictionary, modify the dictionary and write it back out to the Documents directory.

    // get the path to the plist file
    NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
    NSString *documentsPath = [paths objectAtIndex:0]; 
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myfile.plist"];
    
    // read the plist into an NSMutableDictionary
    NSMutableDictionary *plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
    
    // make the additions to the plistDictionary
    
    // write the plist back to the documents directory
    [plistDictionary writeToFile:filePath atomically:YES];
    

    I don't know that you will be able to remove the plist via iTunes.