Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preferredInterfaceOrientationForPresentation crash when displaying in app notification #54

Closed
ldiqual opened this issue Mar 19, 2016 · 6 comments

Comments

@ldiqual
Copy link

ldiqual commented Mar 19, 2016

We're noticing crashes when displaying inapp notifications:

Fatal Exception: UIApplicationInvalidInterfaceOrientation
preferredInterfaceOrientationForPresentation must return a supported interface orientation!

image

We only support portrait orientation.
A quick search in our workspace found this: https://github.com/Appboy/appboy-ios-sdk/blob/master/AppboyKit/headers/AppboyKitLibrary/ABKInAppMessageController.h#L31-L40

It's unclear from the documentation whether orientations are automatically detected

In-app messages will normally support the orientations specified in the app settings

or if all of them are returned by default

The default value of supportedOrientations includes all orientations

Would you mind clarifying the actual behavior and/or sharing the underlying code?

Side note: this is why #44 is important to us.

@Wenzhi
Copy link

Wenzhi commented Mar 19, 2016

Hi @ldiqual,

Here is our orientation-related code for in-app message:

The default values for the supportedOrientations and supportedOrientationMasks are

_supportedOrientations = UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeRight |
        UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationPortraitUpsideDown;
_supportedOrientationMasks = UIInterfaceOrientationMaskAll;

In the in-app message's view controller:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  return self.supportedOrientations;
}
- (NSUInteger)supportedInterfaceOrientations {
  return self.supportedOrientationMasks;
}
- (BOOL)shouldAutorotate {
  return YES;
}

Please note that for the method supportedInterfaceOrientations, the return type should be UIInterfaceOrientationMask; we will update our code. But given that UIInterfaceOrientationMask is NSUInteger according to Apple's documentation, I don't think that is the reason for the crash.

Could you give us more information about how you use in-app message? Do you set the supportedOrientations and/or supportedOrientationMasks of ABKInAppMessageController? What are the steps to reproduce the crash?

Please let me know if you want any more information about code in Appboy.

Thanks,
Wenzhi

@ldiqual
Copy link
Author

ldiqual commented Mar 24, 2016

@Wenzhi Thanks for the followup.

But given that UIInterfaceOrientationMask is NSUInteger according to Apple's documentation, I don't think that is the reason for the crash.

Agreed, that shouldn't matter here.

Could you give us more information about how you use in-app message? Do you set the supportedOrientations and/or supportedOrientationMasks of ABKInAppMessageController?

We don't do anything else other than integrating with segment with the Appboy integration enabled (using Segment-Appboy). We don't set supportedOrientations and co in ABKInAppMessageController. We do have a subclass of ABKFeedViewControllerModalContext (which also doesn't set supportedOrientations) but I believe it is unrelated.

What are the steps to reproduce the crash?

This is where it gets tough. We don't know for sure that it is due to Appboy inapp notifications, however:

  • The crash started appearing in a version where the only change was adding Appboy (via segment, and in a newsfeed tab)
  • Disabling inapp notifications on the server-side solved the issue for some of our users (after uninstalling the app, which I assume clears the inapp notification cache)
  • The only occurrence of preferredInterfaceOrientationForPresentation in our entire workspace is in ABKInAppMessageController.h
  • We reached out to one of our users and asked which orientation they were holding their phone when they started the app, it was landscape (while we support only portrait).

However there is no reference to Appboy in the stacktrace (which is not surprising, it's probably showing a view controller and that call is on the next runloop event). We also can't reproduce the crash (by sending inapp modals to our devices by holding our device in landscape mode).

Would you recommend setting the supported orientation modes manually? Also, why does your documentation indicate "In-app messages will normally support the orientations specified in the app settings" while it seems that they are hardcoded?

@Wenzhi
Copy link

Wenzhi commented Mar 25, 2016

Hi @ldiqual,

About Your Question

why does your documentation indicate "In-app messages will normally support the orientations specified in the app settings" while it seems that they are hardcoded?

Our in-app messages follow the app's orientation settings, even with the default values which support all orientations. Per Apple's supportedInterfaceOrientations documentation:

The system intersects the view controller's supported orientations with the app's supported orientations (as determined by the Info.plist file or the app delegate's application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.

And In preferredInterfaceOrientationForPresentation:

When your view controller supports two or more orientations but the content appears best in one of those orientations, override this method and return the preferred orientation.

Regarding setting the orientation modes manually, it shouldn't make a difference in your case (IAMs will only ever show in portrait). That said, absent any other strong leads at this point, you might try setting that value.

About The Issue

Also - we display an in-app message with a UIWindow on top of the app's window and remove it after the in-app message is dismissed. Are you using any customized UIWIndow, too?

It's also possible this is a Swift-only issue. We'll investigate that avenue further.

Finally, if you have any information about the Devices/OSes that you're seeing this on, any info there would be useful.

Please let me know if you get more information about the crash, and/or if you have any follow-up comments/questions.

Thanks,
Wenzhi

@ldiqual
Copy link
Author

ldiqual commented Mar 25, 2016

Hey @Wenzhi,

That said, absent any other strong leads at this point, you might try setting that value.

Will do this in our next version and report back.

Are you using any customized UIWIndow, too?

We're using a couple libraries that might use their own UIWindow to display content:

I'll take a look at their source code to see if there's something wrong there.

Finally, if you have any information about the Devices/OSes that you're seeing this on, any info there would be useful.

Our 3 affected users:

image
image
image

Full stacktrace:

image

Thanks for tackling this. I'll get back to you if we find more info on this.

@ldiqual
Copy link
Author

ldiqual commented Apr 7, 2016

Doesn't seem to be happening in our new version. Closing for now.

@ldiqual ldiqual closed this as completed Apr 7, 2016
@jinnamohamed1
Copy link

Hi

We have a crash on In-App messaging for large number of users related to preferredInterfaceOrientationForPresentation.

Fatal Exception: UIApplicationInvalidInterfaceOrientation
preferredInterfaceOrientationForPresentation '(7)' must match a supported interface orientation: 'portrait, landscapeLeft, landscapeRight, portraitUpsideDown'!
-[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:]

Our app supports only Portrait and mentioned in the info.plist as “UIInterfaceOrientationPortrait” under UISupportedInterfaceOrientations

I managed to reproduce the issue and explained below

  1. Received In-app message on our app
  2. Pressed home button without doing any action In-App
  3. Opened the app again, then it crashed.

When I debugged, I found that “preferredInterfaceOrientationForPresentation” function of “ABKInAppMessageWindowController” class returns unsupported interface orientation type on resuming the app from background

PS: We are using Appboy version 3.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants