1

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.'
Iman
  • 2,029
  • 2
  • 12
  • 32
Chirag Kothiya
  • 440
  • 3
  • 17

1 Answers1

1

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
}
Mahendra
  • 7,012
  • 2
  • 25
  • 50