Skip navigation
Currently Being Moderated

Creating a email extension for ios... it keeps flipping the orientation of the app when closing.

Dec 21, 2011 1:54 PM

Tags: #email #ios #extension #native #orientation #mfmailcomposeviewcontroller

I know, if I need help I should go post on some apple board... but it's information overflow.... and I am not 100% sure it's related to the extension.

 

Here's the problem

 

I am creating/using an extension to open the MFMailComposeViewController.

 

Now, I figured out how to open it and force it to landscape, but the problem is  when I close the email it, my app flips upside down. (landscape left when it was landscape right before, or vice versa)

 

My app is set to force landscape left and right... and the mail controller does open in landscape... but it's either upside down (landscape right, when the app is left, or vice versa) or when it closes, it flips the application the other way.

 

Has anyone encountered anything like this and ideas on how to fix it?

 

 

My app publish settings, I set to landscape, auto-orient is set to false and it's full screen,

 

However, on start up in code... I am setting stage.autoOrients = true and then using the CustomOrientation.as to control the rotation (to force landscape only)

 

in my extension, I am showing the MFMailComposeViewController in the

 

[[[[UIApplication sharedApplication] keyWindow] rootViewcontroller] presentModalViewcontroller:mailCompser animated:NO];

 

and mailCompser is a subclassed MFMailComposeViewcontroller object and I have set it's override to this:

 

@implementation MailCompose

 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation {

 

    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);

}

 

 

When I launch my app, it starts

 

stage.orientation = rotatedRight

 

 

I then launch my extension and the email page for ios appears, in the correct orientation.... if I rotate the device, both the email and the app rotate to rotatedRight or rotatedLeft correctly.

 

I then click Cancel, delete draft

 

The email window disappears, but now my screen is landscape left.... if I wiggle the device, the sensor picks it up and then rotates the app back right, but this is a major problem.

I am thinking it has something to do with the rootViewController orienatation, but I don't know enough about objC and xcode to know what to do.

 

I have tried googling and searching will little to no luck... but then, the answer could be staring at me and I would have missed it as I am an obj c noob.

 

Anyone know how I can fix this?

 
Replies
  • Currently Being Moderated
    Dec 21, 2011 8:28 PM   in reply to DaveGallant

    Hi Dave:

     

    I doubt if there is correct fix for this. This causes because of the how AIR runtime behaves and handles the rootController which hosts the application(Stage).

     

    But I have a workaround (Drawbacks are small flicker and may not work(work incorrectly) if autoOrients is false.)

     

    Workaround:

     

    When modelViewController(mailComposer) is being dissmissed do [[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];

     

    this should bring your app to correct orientation.

     

    Hope this helps.

     

    Regards,

    Saumitra

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 17, 2012 11:06 AM   in reply to DaveGallant

    Hello Dave,

     

    I tried to follow your solution and in some manner it did help me to restrict the game screen to be in landscape mode only after mail is closed, but what happens is, game screen gets rotated by 180 degree after the mail is closed... i.e. if mail is closed in landscape left, game screen goes to landscape right...

     

    Even though I tried to set Orientation in DID Hide mail composer event then in subsequent calls to mail client it shows 180 degree rotated, not sure what is happening.. Do you have some thoughts to share which I can try?

     

    BTW you can get rid of this "ld: absolute addressing (perhaps -mdynamic-no-pic) used in -[MailComposerHelper mailComposeController:didFinishWithResult:error:] from C:\ ...  \MailExtension.a(MailComposerHelper.o) not allowed in slidable image. Use '-read_only_relocs suppress' to enable text relocs Compilation failed while executing : ld64"

     

    just by adding UIKit framework in your target. Xcode->Target Project Setting->General->Add framework... (as UIDeviceOrientationDidChangeNotification is defined in UIKit's UIDevice class)...

     

     

    Best Wishes,

    Sanniv

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 17, 2012 11:48 AM   in reply to sanniv_ios

    Hi:

     

    Even though I tried to set Orientation in DID Hide mail composer event then in subsequent calls to mail client it shows 180 degree rotated, not sure what is happening.. Do you have some thoughts to share which I can try?

     

    Did you try posting a notification(As described in thread above) instead setting orientation?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 18, 2012 2:24 AM   in reply to Saumitra Bhave

    Hi Soumitra, I did tried adding notification, but didn't help. same result..

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2012 6:55 AM   in reply to DaveGallant

    Hi,

     

    I had the same problem and found the following workaround: apart from overriding MFMailComposeViewController's shouldAutorotateToInterfaceOrientation, I also added implementations for

     

    _preferredInterfaceOrientationGivenCurrentOrientation

     

    and

     

    _isSupportedInterfaceOrientation

     

    in a category of UIViewController in the native code.

     

    Then, in the Actionscript code, added an event listener for StageOrientationEvent.ORIENTATION_CHANGING (with high priority and use_capture = true) in Actionscript to prevent resizing of the stage, which can occur even if the orientation doesn’t change.

     

    This fixed it for me, but, as it messes with UIViewController, it makes it tricky to have views which have different orientation behaviour (if you want one view to be able to rotate in all directions, but others only to support Landscape, for example).

     

    I've posted details and example code here: http://blog.diadraw.com/native-extensions-for-mobile-air-apps-getting- round-the-orientation-issue/

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points