Your call to -[NSData writeToFile:atomically:]
is failing because you are not providing a writeable path. Try this:
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
NSURL *imageURL = [documentsURL URLByAppendingPathComponent:@"SOS_Map.png"];
[data writeToURL:imageURL atomically:YES];
Then, to load and share the image:
NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
NSURL *imageURL = [documentsURL URLByAppendingPathComponent:@"SOS_Map.png"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
NSArray *itemsToShare = @[@"text", image];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
Another, possibly simpler solution would be to keep the captured image in memory.