I'm importing an image from the Mail app to my own app, I get the image and try to send it to my main view controller through AppDelegate. I can use NSLog@ to confirm the image is going through, but when I try to use it it shows as null. Here's my code:
In AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if (url !=nil && [url isFileURL]) {
MainViewController *view = [[MainViewController alloc] init];
[view handleDocumentOpenURL:url];
NSLog(@"Url 1: %@", url); // Url appears
}
return YES;
}
In my MainViewController.m
- (void)handleDocumentOpenURL:(NSURL *)url {
NSData *imageData = [NSData dataWithContentsOfURL:url];
self.importedImage = [UIImage imageWithData:imageData];
NSLog(@"Image %@", self.importedImage); // Shows the object exists
}
The problem is that if I try to access this UIImage (self.importedImage) from other methods it says that it is null (it works within the above mentioned method).
Additional info:
I declare the importedImage
as a UIImage on my MainViewController.h file.
I assume my AppDelegate might not be accessing the actual MainViewController but a copy of it. I've looked around for an answer and couldn't find anything, any help is appreciated.