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

setPreferredOrientations not working in iPad #27235

Closed
dark-chocolate opened this issue Jan 29, 2019 · 17 comments
Closed

setPreferredOrientations not working in iPad #27235

dark-chocolate opened this issue Jan 29, 2019 · 17 comments
Labels
framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically

Comments

@dark-chocolate
Copy link

dark-chocolate commented Jan 29, 2019

Steps to reproduce:

void main() => runApp(MyPage());

class MyPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); // doesn't seem to work in iPad
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("AppBar")),
        body: Text("Text"),
      ),
    );
  }
}

You can still rotate your iPad. However it works fine in iPhone.


Flutter Doctor

[✓] Flutter (Channel beta, v1.0.1-pre.1, on Mac OS X 10.14 18A389, locale en-GB)
    • Flutter version 1.0.1-pre.1 at /flutter
    • Framework revision 2f60afca7a (4 weeks ago), 2018-12-29 14:11:09 +0530
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/chocolate/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1248-b01)

[✓] Connected device (1 available)
    • iPad Pro • b1910da0802b3d6e38b23a455f95878f0ca87733 • ios • iOS 12.0.1
@zoechi
Copy link
Contributor

zoechi commented Jan 29, 2019

Might be #13238

@zoechi zoechi added platform-ios iOS applications specifically framework flutter/packages/flutter repository. See also f: labels. labels Jan 29, 2019
@zoechi zoechi added this to the Goals milestone Jan 29, 2019
@zoechi zoechi added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 29, 2019
@dark-chocolate
Copy link
Author

Thanks @zoechi , I did read that thread before creating a new issue here. However that is related to automatically setting orientation and mine one is a bug which only occurs in iPad.

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 29, 2019
@zoechi
Copy link
Contributor

zoechi commented Jan 29, 2019

Rotating like mentioned in #13238 also does not fix the orientation on your iPad?

@dark-chocolate
Copy link
Author

@zoechi Yes, it doesn't lock the orientation. I can rotate from landscape to portrait and vice versa for the whole day. As I said before, it works as expected in iPhone.

@SergioBernal8
Copy link

I manage to fix that problem with this:

First, add this code to the appDelegate.swift in the Runner project

override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask(arrayLiteral: [UIInterfaceOrientationMask.landscapeLeft,UIInterfaceOrientationMask.landscapeRight]); }

Second Check that "Requires full screen" is enabled under Targets->Runner->Deployment info

Screen

Please, take into account that I'm not deploying for iPhone and I have not tested that in iPhone, even though, I think it also should work in iPhone.

@dark-chocolate
Copy link
Author

@SergioBernal8 Thanks for your solution, I haven't tried it yet though, but I want Flutter team to solve the bug instead of any workaround.

@sjoenk
Copy link

sjoenk commented Jun 24, 2019

+1
I'm having the exact same issue. It's working fine on iPhone but on iPad you can rotate in all directions.

@dark-chocolate
Copy link
Author

@sjoenk Please show your +1 support by putting a thumbs up to the issue, that adds more priority to the issue.

@0xVesion
Copy link

0xVesion commented Jul 3, 2019

I manage to fix that problem with this:

First, add this code to the appDelegate.swift in the Runner project

override func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask(arrayLiteral: [UIInterfaceOrientationMask.landscapeLeft,UIInterfaceOrientationMask.landscapeRight]); }

Second Check that "Requires full screen" is enabled under Targets->Runner->Deployment info

Screen

Please, take into account that I'm not deploying for iPhone and I have not tested that in iPhone, even though, I think it also should work in iPhone.

That actually fixed it for me. Only thing is that i now have to run my app in fullscreen. That's fine for my use case but could be annoying for others.

@lwky
Copy link

lwky commented Jul 7, 2019

We fixed it by setting UISupportedInterfaceOrientations in Info.plist
this value is set by the DeviceOrientation checkbox in your xcode project, but beneath it is:
<key>UISupportedInterfaceOrientations~ipad</key>
with separate values for iPad.

in our case, setting both to

<array>
	<string>UIInterfaceOrientationPortrait</string>
</array>

resulted in all iOS devices remaining in portrait mode.

@josh-ksr
Copy link
Contributor

@dark-chocolate i also noticed this behavior lately and did some additional research:

All iPad apps that support multitasking need to support all interface orientations (check this apple guide).

As it seems, the only way to restrict interface orientations for iPad is to opt out of multitasking completely as described above ( Set "Requires full screen"). After opting out, the app will not support Slide Over and Split View multitasking anymore.

From my perspective, this is not a Bug but the documentation could possibly be improved. Might make sense to add some information about this behavior here

@dark-chocolate
Copy link
Author

@josh-ksr Thank you so much for sharing this, you're right it's not a bug, and Flutter team should update documentation regarding this. Once they do, they can close this issue.

@DanTup
Copy link
Contributor

DanTup commented Oct 15, 2019

Docs were updated by #40743.

@DanTup DanTup closed this as completed Oct 15, 2019
@renanyoy
Copy link

just need to check "full screen" option after

SystemChrome.setPreferredOrientations();

works as expected, and can be dynamically changed.

@SinoMiles
Copy link

@dark-chocolate did you fix the problem?i'm using ipad too,can't lock orientation.

@matpag
Copy link

matpag commented Jun 29, 2021

I've finally fixed it by manually editing the Info.plist file.

Open it with a text editor and change the supported orientation values you find with those:

<key>UISupportedInterfaceOrientations</key>
<array>
  <string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
  <string>UIInterfaceOrientationPortrait</string>
</array>

The first block is for iPhone, the second one for iPad (this will block the multitasking)

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically
Projects
None yet
Development

No branches or pull requests