I've got an NSData object, that I am placing inside a dictionary. I am then writing the dictionary to the documents directory. Then I'm immediately making the URL to the file available to the uiactivityviewcontroller so that it is included for attachment in the Mail app.
The problem is that when the user clicks on this file for import into the app, everything in the dictionary is available (there are other NSString objects) except the NSData object! When I test to see what is inside the object for the relevant key that should hold the NSData object, it returns (null)..
Here are the relevant bits of the code (I've simplified some of it for clarity, but it's essentially the same code):
NSDictionary *dictionaryItems = @{@"stringobj": @"string",
@"dataobj": dataobject};
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSURL *dictUrl = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:@"myinfo.myappinfo"]]; //my app will open this file type
[dictionaryItems writeToURL:dictURL atomically:YES];
// I will include the dictURL in the activityitems array so it can be attached to the the email when the uiacitivityitemcontroller is presented
When the app is opened, I simply load the dictionary from the file, and attempt to retrieve the nsdata object from the "dataobj" key.. but it returns null.
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url !=nil && [url isFileURL]) {
self.importedDictionary = [NSDictionary dictionaryWithContentsOfURL:url];
NSLog("%@",[self.importedDictionary objectForKey:@"dataobj"]); //returns null.. why?
}
}
I'm not sure why the NSData object I placed in the dictionary isn't there - any thoughts? Any help appreciated!