Note that there are some explanatory texts on larger screens.

plurals
  1. POIos MFMailComposeViewController not displaing
    primarykey
    data
    text
    <p>I trying to write rhodes native extension extension for opening <em>iOS MailComposer</em>. Now code "works", but <em>MFMailComposeViewController</em> not displaying and xcode shows warning:</p> <pre><code>Attempt to present &lt;MFMailComposeViewController: 0x12b60840&gt; on &lt;Iosmailto: 0xc1898d0&gt; whose view is not in the window hierarchy! </code></pre> <p>I read that UIViewControllers must be in hierarchy, but i can't provide this from Rhodes ruby code or clear-C extension wrapper. Now i'm trying to present my <em>UIViewController</em> with <em>MFMailComposeController</em> from <em>[UIApplication sharedApplication].keyWindow.rootViewController</em> but mail composer not show yet.</p> <p>interface from iosmailto.h:</p> <pre><code>@interface Iosmailto : UIViewController&lt;MFMailComposeViewControllerDelegate&gt; { } @property(nonatomic, assign) id delegate; //-(IBAction)send_mail:(id)sender; @end </code></pre> <p>implementation from iosmailto.m:</p> <pre><code>@implementation Iosmailto - (void)viewDidLoad { [super viewDidLoad]; [self send_mail]; } - (void)send_mail { if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; composer.mailComposeDelegate = self; [composer setSubject:[NSString stringWithUTF8String:subj]]; NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]]; [composer setToRecipients:recipients_array]; NSString *composerBody = [NSString stringWithUTF8String:message]; [composer setMessageBody:composerBody isHTML:NO]; [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [self presentModalViewController:composer animated:YES]; [composer release]; } else { NSLog(@"Device is unable to send email in its current state."); } } /* some unnecessary for this question methods */ @end </code></pre> <p>And C function defined in iosmailto.m thats called from Rhodes:</p> <pre><code>// find root vc UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; // find topmost vc while (topController.presentedViewController) { topController = topController.presentedViewController; } iosmailer = [[Iosmailto alloc] init]; iosmailer.delegate = topController; [topController presentViewController:iosmailer animated:YES completion:nil]; </code></pre> <p>This app is not for AppStore. Hacks is welcome if needed.</p> <p><strong>Update</strong> init for Iosmailto:</p> <pre><code>- (id)init { self = [super initWithNibName:nil bundle:nil]; return self; } </code></pre> <p><strong>Update 2</strong> The short version of this code (without UIViewController wrapper) was my starting point. That's don't work too. And this have the same warning and one more:</p> <pre><code>UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; while (topController.presentedViewController) { topController = topController.presentedViewController; } if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; composer.mailComposeDelegate = (id&lt;MFMailComposeViewControllerDelegate&gt;)topController ; [composer setSubject:[NSString stringWithUTF8String:subj]]; NSArray *recipients_array = [NSArray arrayWithObject:[NSString stringWithUTF8String:recipients]]; [composer setToRecipients:recipients_array]; NSString *composerBody = [NSString stringWithUTF8String:message]; [composer setMessageBody:composerBody isHTML:NO]; [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [topController presentModalViewController:composer animated:YES]; [composer release]; } else { } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload