Reputation: 1099
While share image like normal image it will work fine. But when getting image from UIImageView
and share it throwing an error.
how to resolve this issue?
and share image.
Where is issue in my code.
NSString * title =[NSString stringWithFormat:@"Address: \n %@",self.label.text];
UIImage *image = self.imageView.image;
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:@[title, image] applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypeAirDrop];
[self presentViewController:activityViewController animated:YES completion:^{}];
Error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[MFMailComposeInternalViewController addAttachmentData:mimeType:fileName:] attachment must not be nil.'
Upvotes: 1
Views: 1399
Reputation: 8904
Your attach that you are sharing is nil
, is the reason you are getting a crash at run time.
before attaching an attachment you need to check wether attachment file is available or not.
for eg.
if (self.imageView.image == nil) {
NSLog("image not available.")
return
}
Upvotes: 1