Skip to content

Commit

Permalink
[ios] fix orientation when launched in landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Willoughby committed Aug 13, 2015
1 parent 7226982 commit d33ba13
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ios/CDVBarcodeScanner.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,11 @@ - (BOOL)shouldAutorotate

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector (preferredInterfaceOrientationForPresentation)])
{
return [self.orientationDelegate preferredInterfaceOrientationForPresentation];
}
return UIInterfaceOrientationLandscapeRight;
}

- (NSUInteger)supportedInterfaceOrientations
Expand Down

1 comment on commit d33ba13

@convey-mane
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, probably the following doesn't matter at all (as it can be assumed, that the if in line 1038 always resolves to true, isn't it), but from a programmer's perspective …

let's assume, this method (preferredInterfaceOrientationForPresentation) comes through to it's "fallback" return UIInterfaceOrientationLandscapeRight; in line 1042;
and as we then also can assume, that supportedInterfaceOrientations (line 1045) maybe also gets to it's "fallback" in line 1051 (return UIInterfaceOrientationMaskPortrait;):
these two don't work together, the app will crash with

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

And, on the other hand: why force the BarcodeScanner to a certain starting orientation at all?
In our fork of the "now official repository" of this plugin, I simply omit preferredInterfaceOrientationForPresentation.
If BarcodeScanner is allowed to rotate (via shouldAutorotate) and the actual device orientation is possible (from supportedInterfaceOrientations *), why not simply let it open in that orientation.

*: I also implemented that "fallback" in line 1051 as

return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? UIInterfaceOrientationMaskAllButUpsideDown : UIInterfaceOrientationMaskAll);

so that all normal standard orientations are possible. This also better fits to the "fallback" of shouldAutorotate, which returns YES in line 1033.
But that maybe should be "made […] configurable", as you suppose in the parent commit.

Please sign in to comment.