2014-07-18 49 views
8

Cordova 3.5.0-0.2.6 (son kararlı sürüm) kullanıyorum. iPad aygıtlarının yönünü kilitleme konusunda sorun yaşıyorum. iPhone'da düzgün çalışıyor ancak iPad'de yönelim kilitlenmiyor.Cordova kilit yönelimi başarısız oluyor

Sadece sayfaları değil, tüm uygulamayı kilitlemek istiyorum.

Bu benim şimdiki Config.xml geçerli: oluşturulan Plist dosyası benziyor

<?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

Bu, Cordova'daki bir hatadan kaynaklanıyor - https://issues.apache.org/jira/browse/CB-6026 Henüz düzeltilmemiş yönlendirmeyle ilgili daha büyük bir hata var - https: // issues.apache.org/jira/browse/CB-6462 – Mauro

cevap

2

bu hatadan çözümlerden çok çalıştı, ama bunların çoğu başarısız oldu. Neyse ki, ekran yönlendirmesini JavaScript aracılığıyla başarıyla kilitlemenizi sağlayan bir Cordova eklentisi buldum. IPad'de de çalışıyor. cordova plugin add net.yoik.cordova.plugins.screenorientation

  • Kilit JavaScript screen.lockOrientation('portrait-primary') kullanarak ekran:

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

    1. eklentisini ekleyin

      . Belgenin deviceready çalışmasının ardından bu işlevi çağırdığınızdan emin olun.
  • 2

    Etrafında bir parça bir parça, ama buna yaklaşmanın bir yolu Cordova kancaları üzerinden. Örneğin, hooks/before_compile dizinde bu yerleştirin:

    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"); 
        } 
    }); 
    

    iOS (cordova build ios) için inşa artık otomatik plist değiştirmek gerekir.

    +0

    Çok iyi bir fikir, çünkü hala benim için çalışmıyor. Kullanmak zorunda: p = p.replace ( "", " \ n \ t \ t UISupportedInterfaceOrientations ~ \ n \ t \ n \ \ t UIInterfaceOrientationPortrait \ n \ iphone \ t \ t \ n \ t \ t UISupportedInterfaceOrientations ~ ipad \ n \ \ t \ n \ \ t UIInterfaceOrientationPortrait \ n \ \ t UIInterfaceOrientationLandscapeLeft \ n \ \ t UIInterfaceOrientationLandscapeRight \ n \ t \ t \ n \ t " ); –

    İlgili konular