You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/06/18 12:20:14 UTC

[GitHub] [cordova-plugin-screen-orientation] schoetty commented on issue #43: Screen doesn't rotate many times on iOS from landscape to portrait

schoetty commented on issue #43: Screen doesn't rotate many times on iOS from landscape to portrait
URL: https://github.com/apache/cordova-plugin-screen-orientation/issues/43#issuecomment-503079471
 
 
   I use a somehow hackish but working workaround in one of my projects. It consists of two parts. The first is a fork of this repo with adjusted code for iOS. The second is a little script being invoked during build as cordova hook. It has a bit of "works for me" character. With this being said, here it is:
   
   The plugin: https://github.com/codevise/cordova-plugin-screen-orientation
   
   And the hook-script:
   ```
   /*global require, module, __dirname, console*/
   
   var insertAfter = require('./utils/insertAfter');
   
   var mainViewController = __dirname + '/../platforms/ios/<your-project-name>/Classes/MainViewController.m';
   var headMarker = "#import \"MainViewController.h\"\n";
   var bodyMarker = "#pragma mark View lifecycle\n";
   
   module.exports = function(context) {
     console.log('Overriding supported orientations...');
   
     insertAfter(mainViewController,
                 headMarker,
                 "#import \"CDVOrientation.h\"\n"
     );
   
     insertAfter(mainViewController,
                 bodyMarker,
                 "\n- (NSUInteger) supportedInterfaceOrientations\n" +
                 "{\n" +
                 "    return (unsigned long)[CDVOrientation allowedOrientations];\n" +
                 "}\n"
     );
   };
   ```
   
   Don't forget to adjust the path for the MainViewController to match your project structure and save it to `scripts/override_supported_orientations_for_ios.js` within your cordova project.
   Then add the script as hook in the `config.xml`:
   
   ```
   <platform name="ios">
     <hook src="scripts/override_supported_orientations_for_ios.js" type="after_prepare" />
   ...
   ```
   
   Again, this doesn't claim to be a solution, just a way to "get it done".

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org