2014-07-18 5 views
8

코드바 3.5.0-0.2.6 (마지막 안정 버전)을 사용하고 있습니다. iPad 기기의 방향을 고정시키는 데 문제가 있습니다. iPhone에서 제대로 작동하지만 iPad에서는 방향이 고정되지 않습니다.iPad에서 코르도바 잠금 장치 방향이 잘못되었습니다.

페이지가 아닌 전체 앱을 잠그고 싶습니다.

이 내 현재 config.xml에 있습니다 : 생성 된 PLIST 파일처럼 보이는

<?xml version="1.0" encoding="utf-8"?> 
<widget id="com.domain" 
     version="version" 
     xmlns="http://www.w3.org/ns/widgets"> 
    <name>xxx</name> 

    <description>Lorem ipsum</description> 

    <access origin="*"/> 

    <author email="[email protected]" href="https://x.com">x</author> 

    <content src="index.html?platform=cordova"/> 

    <feature ...></feature> 

    <preference name="permissions" value="none"/> 
    <preference name="orientation" value="portrait"/> 
    <preference name="show-splash-screen-spinner" value="true"/> 
    <preference name="auto-hide-splash-screen" value="true"/> 
    <preference name="prerendered-icon" value="true"/> 
    <preference name="disallowoverscroll" value="true"/> 
    <preference name="webviewbounce" value="false"/> 

    <preference name="StatusBarOverlaysWebView" value="false"/> 
    <preference name="StatusBarBackgroundColor" value="#000000"/> 
</widget> 

:

<key>UISupportedInterfaceOrientations</key> 
<array> 
    <string>UIInterfaceOrientationPortrait</string> 
</array> 
<key>UISupportedInterfaceOrientations¨ipad</key> 
<array> 
    <string>UIInterfaceOrientationPortrait</string> 
    <string>UIInterfaceOrientationLandscapeLeft</string> 
    <string>UIInterfaceOrientationPortraitUpsideDown</string> 
    <string>UIInterfaceOrientationLandscapeRight</string> 
</array> 
+2

이것은 Cordova의 버그로 인한 것입니다 - https://issues.apache.org/jira/browse/CB-6026 아직 수정되지 않은 더 큰 버그가 있습니다 - https : // issues.apache.org/jira/browse/CB-6462 – Mauro

답변

2

내가이 버그에 해결 방법을 많이 시도했지만 대부분 실패했습니다. 다행히도 JavaScript를 통해 화면 방향을 성공적으로 잠글 수있는 Cordova 플러그인을 발견했습니다. iPad에서도 잘 작동합니다. cordova plugin add net.yoik.cordova.plugins.screenorientation

  • 잠금 자바 스크립트에 screen.lockOrientation('portrait-primary')을 사용하여 화면 :

    https://github.com/yoik/cordova-yoik-screenorientation

    1. 플러그인을 추가

      . 문서의 deviceready이 해고 된 후에이 함수를 호출해야합니다.
  • 2

    해킹 비트이지만이 문제를 해결하기위한 방법 중 하나는 코르도바 후크입니다. 예를 들어, hooks/before_compile 디렉토리에이 장소 :

    var fs = require('fs'); 
    var plist = './platforms/ios/YourProjectName/YourProjectName-Info.plist'; 
    fs.exists(plist, function (exists) { 
        if (exists) { 
         var p = fs.readFileSync(plist, 'utf8'); 
         p = p.replace(
          /<key>(UISupportedInterfaceOrientations(\~ipad)*)<\/key>[\r\n ]*<array>[\s\S]*?(?=<\/array>)/ig, 
          "<key>$1</key>\n\t<array>\n\t\t<string>UIInterfaceOrientationLandscapeLeft</string>\n\t\t<string>UIInterfaceOrientationLandscapeRight</string>\n\t" 
         ); 
         fs.writeFileSync(plist, p, "utf8"); 
        } 
    }); 
    

    당신이 아이폰 OS (cordova build ios)에 대한 구축 지금은 자동으로 PLIST을 변경해야합니다.

    +0

    아직 나에게 적합하지 않다는 것을 고려하면 아주 좋은 생각입니다. 내가 사용했다 : P = p.replace ( "" 을 " N \ \ t \ t UISupportedInterfaceOrientations ~ n \ t \ t \ n \ t \ t UIInterfaceOrientationPortrait \ n \ 아이폰 \ t \ t \ n \ t \ t UISupportedInterfaceOrientations ~ 아이 패드 \ n \ t \ t \ n \ t \ t UIInterfaceOrientationPortrait \ n \ t \ t UIInterfaceOrientationLandscapeLeft \ n \ t \ t UIInterfaceOrientationLandscapeRight \ n \ t \ t \ n \ t " ); –

    관련 문제