user717452
user717452

Reputation: 111

Mail Composer Won't Launch From UIPreviewAction

In the view controller for my Peek view of an app I have:

- (NSArray*)previewActionItems {  

    /  
    UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Post to Facebook" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {  


    }];  

    UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"Message" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {  


    }];  

    UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"Email" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {  
        [self displayComposerSheet];  


    }];  

    /  
    NSArray *actions = @[action1, action2, action3];  

    /  
    return actions;  
} 

This successfully allows me to pull up a sheet of preview actions after a 3D Touch. displayComposerSheet is:

-(void)displayComposerSheet  
{  
    NSLog(@"Mail Button Pressed");
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];  
    picker.mailComposeDelegate = self;  

    [picker setSubject:@"Check out this article from Fritch"];  


    /  
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];  

    [picker setToRecipients:toRecipients];  

    /  
    NSString *emailBody = self.finalObject.articleImage;  
    [picker setMessageBody:emailBody isHTML:YES];  

    [self presentViewController:picker animated:YES completion:nil];  
    [picker release];  
} 

However, the mail composer never is presented. Please help.

Upvotes: 1

Views: 574

Answers (1)

Rory McKinnel
Rory McKinnel

Reputation: 8014

The issue is probably that the view hierarchy is not normal when the Peek view is shown.

Try using the root view controller to present the picker:

[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:picker animated:YES completion:nil];

Upvotes: 10

Related Questions