Search code examples
uiwebviewmfmailcomposeviewcontroller

Mail composer didn't display under my UIWebView


I have a MainController and detailedcontroller. When I popover the Book selection and select a Book, the detailcontroller display an UIWebView with the book articles :

@interface IpadBooksViewController : UITableViewController {
    SearchResult                *searchResult;
    IpadArticleViewController   *detailController;
    IpadMainViewController      *mainController;
    UIPopoverController         *popover;
}

Into the UIWebView, I display an Email icon and catch the scheme :

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

    NSURL *url          = [request URL];
    NSString *scheme    = [url scheme];
    NSString *host      = [url host];

    if ([[url description] hasSuffix:@"next"]) {
        NSLog(@"next Show");
    }

    BOOL isShareLinks       = [host isEqualToString:@"displayShareLinks"];
    BOOL isFavoriteLinks    = [host isEqualToString:@"displayFavoriteLinks"];

    if ([@"myappurl" isEqualToString:scheme] && (isShareLinks || isFavoriteLinks)) {        

        self.selectedArticleNumber  = [url.path lastPathComponent];

        if (isShareLinks) {                     
            [self sendMailArticleNumber:selectedArticleNumber];

        } else if (isFavoriteLinks) {
            NSLog(@"ipad favorite clicked");
            [self toggleFavorite:selectedArticleNumber];

            Broker *broker = [[Broker alloc] init];
            [broker loadProjects:self];
            [broker release];            
        }
    }

    return [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];

}

Action is supposed to display the MFMailController under my UIWebView, but nothing is displayed without error message :

- (void) sendMailArticleNumber:(NSString *)articleNumber {
    MFMailComposeViewController* composer = [[MFMailComposeViewController alloc] init];
    composer.mailComposeDelegate = self;
    [composer setSubject:@"Article"];

    NSString *messageBody = [Article fetchBody:articleNumber bookId:bookId];

    [composer setMessageBody:messageBody isHTML:YES];   
    [self presentModalViewController:composer animated:YES];

    [composer release];     
}

Any help will be welcomed. I did try creating a popover, addView atIndex without success ... Let me know if you need more code.

David


Solution

  • I did solve the issue by loading the controller into the delegate as following :

        [((PublilexAppDelegate*)[[UIApplication sharedApplication] delegate]) sendMailArticleNumber:selectedArticleNumber bookId:self.bookId];
    

    And then into the Delegate :

    - (void) sendMailArticleNumber:(NSString *)articleNumber bookId:(NSString*)bookId {
        MFMailComposeViewController* composer = [[MFMailComposeViewController alloc] init];
        composer.mailComposeDelegate = self;
        [composer setSubject:@"Article"];
    
        NSString *messageBody = [Article fetchBody:articleNumber bookId:bookId];
    
        [composer setMessageBody:messageBody isHTML:YES];
        [self->navigationController presentModalViewController:composer animated:YES];
    
        [composer release];
    }
    

    And to dismiss and comeback to the previous view :

    -(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    
        [self->navigationController dismissModalViewControllerAnimated:YES];
    
        //    [self dismissViewControllerAnimated:YES completion:nil];
    
        //    [((PublilexAppDelegate*)[[UIApplication sharedApplication] delegate]) navigateToIpadMain];
    
    }