0

I have a problem with the UIActivityViewController on iPad

Here is my Code:

NSString* someText = @"Hi, I am using the official iEveryThing Tech app #iEveryTech";
        NSString* Website = [NSURL URLWithString:@"https://itunes.apple.com/us/app/ieverytech/id578148847?l=de&ls=1&mt=8"];
        NSArray* dataToShare = @[someText,Website];

        Class activityViewController = NSClassFromString(@"UIActivityViewController");

        if(activityViewController) {
            UIActivityViewController* activityViewController =
        [[UIActivityViewController alloc] initWithActivityItems:dataToShare
                                          applicationActivities:nil];
            [self presentViewController:activityViewController animated:YES completion:nil];}



        }

On iPhone the Mail composer View will disappear after sending the mail but not the Composer on the iPad here is my Composer:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {

    if (error) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error"

                                                        message:[NSString stringWithFormat:@"error %@", [error description]]

                                                       delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];

        [alert show];


        [self dismissModalViewControllerAnimated:YES];

    }

    else {

        [self dismissModalViewControllerAnimated:YES];

    }

}
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98

2 Answers2

1

The activityViewController use a native method for send mail don't need use mailComposeController, like this

NSMutableArray *items = [NSMutableArray new];
    [items addObject:@"text for share"];
    [items addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:self.imagePath]]];

NSArray *activityItems = [NSArray arrayWithArray:items];

self.activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:[NSArray arrayWithObjects:whatsapp,instagram, nil]];

self.activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint,UIActivityTypeAirDrop,UIActivityTypeCopyToPasteboard];

[self presentViewController:self.activityVC animated:YES completion:nil];
Claudia Mardegan
  • 567
  • 4
  • 14
0

First thing, when using the activityViewController, your class is not the delegate for the mail composer and the code will not be called. This is all handled internally in the activityViewController.

As for your view not being dismissed, implement the complete block call for the activityViewController. In the block be sure to dismiss the view controller.