2016-04-04 40 views
1

我有一個與DevExpressPhoneGap開發的混合應用程序。iOS上的PhoneGap應用程序中的window.open:此應用程序不允許查詢方案文件

我試着通過

window.open('file:///var/mobile/Containers/Data/.../image.jpg', '_system'); 

打開本地JPEG圖像,但它不工作(再)iPhone和iPad(最新的iOS版本9),與錯誤error: "This app is not allowed to query for scheme file"失敗。

(該應用程序通過PhoneGap的方法FileTransfer.download來,它通過window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, ...)方法得到的文件夾中下載的圖像事先)

它正常工作在Android,它在iPhone上,以及在幾個星期前工作正常。由於DevExtreme的更新,我認爲它可能與PhoneGap更新有關。

之前,我用PhoneGap 3.7.0,現在我用cli-5.2.0

我已經找到這個問題(https://www.devexpress.com/Support/Center/Question/Details/Q486439),這個問題是相似的,但它已經2歲了,似乎並沒有解決我的問題。

使用GapDebug,我看到這個在日誌中:

<Warning>: THREAD WARNING: ['InAppBrowser'] took '38.211914' ms. Plugin should use a background thread. 
<Warning>: THREAD WARNING: ['File'] took '26.509033' ms. Plugin should use a background thread. 
<Warning>: -canOpenURL: failed for URL: "file:///var/mobile/Containers/Data/Application/9425CCB6-77F7-4337-B37C-7DB577C2F6B4/Documents/myDocuments/a96e7238-a502-49e6-bcd3-186937afc3cb/camera_1458208164206.jpg" - error: "This app is not allowed to query for scheme file" 

這是某種權限的問題,但什麼添加到config.xml?

這是我的config.xml:

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.devexpress.apptemplate" version="1.0" versionCode="1"> 
    <name>ApplicationTemplate</name> 
    <preference name="phonegap-version" value="cli-5.2.0" /> 
    <preference name="permissions" value="none" /> 
    <preference name="prerendered-icon" value="true" /> 
    <preference name="android-windowSoftInputMode" value="adjustResize" /> 
    <preference name="SplashScreen" value="splash" /> 
    <preference name="SplashScreenDelay" value="60000" /> 
    <preference name="AutoHideSplashScreen" value="false" /> 
    <preference name="DisallowOverscroll" value="true" /> 
    <preference name="StatusBarOverlaysWebView" value="false" /> 
    <preference name="StatusBarBackgroundColor" value="#000000" /> 
    <preference name="KeyboardDisplayRequiresUserAction" value="false" /> 
    <feature name="http://api.phonegap.com/1.0/network" /> 
    <gap:plugin name="com.devexpress.plugins.devextremeaddon" version="1.0.1" /> 
    <gap:plugin name="cordova-plugin-ios-longpress-fix" version="1.1.0" source="npm" /> 
    <gap:plugin name="org.apache.cordova.camera" version="0.3.6" /> 
    <gap:plugin name="org.apache.cordova.file" version="1.3.3" /> 
    <gap:plugin name="org.apache.cordova.file-transfer" version="0.5.0" /> 
    <gap:plugin name="org.apache.cordova.inappbrowser" version="0.6.0" /> 
    <gap:plugin name="org.apache.cordova.media-capture" version="0.3.6" /> 
    <gap:plugin name="org.apache.cordova.media" version="0.2.16" /> 
    <gap:plugin name="org.apache.cordova.network-information" version="0.2.15" /> 
    <gap:plugin name="cordova-plugin-statusbar" version="2.1.0" source="npm" onload="true" /> 
    <gap:plugin name="org.apache.cordova.splashscreen" version="1.0.0" onload="true" /> 
    <access origin="*" subdomains="true"/> 
    <gap:plugin name="cordova-plugin-whitelist" source="npm"/> 
    <allow-navigation href="*" /> 
    <allow-intent href="*" /> 
</widget> 

我甚至增加了兩行

<allow-navigation href="*" /> 
    <allow-intent href="*" /> 

根據https://github.com/apache/cordova-plugin-whitelist,並沒有幫助。

我看到離子,另一種混合架構,還提到了自己的文檔http://docs.ionic.io/docs/cordova-whitelist可能存在權限問題與新的PhoneGap版本,如CLI版本,並且,上述<allow-navigation href="*" />應使用 - 但它似乎並沒有幫助我的情況。

===更新===

我創建了的PhoneGap的&科爾多瓦的github上兩張票:

===更新2 ===

如以下建議,我現在使用https://github.com/pwlin/cordova-plugin-file-opener2而不是,它工作正常。

+1

我面臨同樣的問題.. 。我開始使用cordova-plugin-file-opener2(https://github.com/pwlin/cordova-plugin-file-opener2)來避免這個問題。 – gmartini20

+0

@ gmartini20謝謝,這也適用於我:) –

+0

@ gmartini20你會讓你的評論一個答案?順便說一句:file-opener2插件似乎有問題,其中有空格的文件路徑 - window.open()不。 –

回答

1

我正面臨同樣的問題......我開始使用cordova-plugin-file-opener2(github.com/pwlin/cordova-plugin- file-opener2)來避免這個問題。

要使用空格我刪除他們從TARGETPATH解決的問題:

targetPath = targetPath.replace(/ /g,'') 

所以我下載/開放代碼就是這樣:

$cordovaFileTransfer.download(url, targetPath, options, trustHosts) 
    .then(function(result) { 
    $cordovaFileOpener2.open(targetPath, mimeType) 
    }) 
+0

我想保留原來的名字。我在下載文件時使用encodeURI解決了這個問題。 https://github.com/pwlin/cordova-plugin-file-opener2/issues/53 –

2

在iOS 9上,您必須配置要查詢的網址(瞭解是否可以打開它們)。

要做到這一點,你必須編輯的info.plist並添加LSApplicationQueriesSchemes鍵,用您想查詢

<key>LSApplicationQueriesSchemes</key> 
<array> 
<string>file</string> 
<string>whatsapp</string> 
<string>...</string> 
</array> 

當您使用科爾多瓦,你可以做的是,在方案的字符串數組幾種不同的方式。

您可以在平臺/ ios中打開Xcode項目並編輯info.plist文件,但在某些情況下Xcode項目會被刪除並重新創建,您的更改將會丟失。

另一種選擇是創建一個簡單的cordova插件,只需在info.plist上寫入即可。要做到這一點,你必須使用配置文件標籤上的plugin.xml

<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes"> 
    <array> 
     <string>file</string> 
    </array> 
</config-file> 

http://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#platform

第三個選項是使用一個鉤子,鉤子是一個腳本文件(節點時,bash)是執行,你可以用它來寫info.plist http://cordova.apache.org/docs/en/latest/guide/appdev/hooks/index.html

+0

我正在使用Visual Studio與DevExtreme(http://js.devexpress.com/) (無XCode),最終使用PhoneGap。在那裏,我只使用了一些cordova插件(例如白名單)。我的項目中沒有任何info.plist文件。 (對不起,這是我的第一個使用Phonegap/Cordova的混合應用程序)。但是,我可能會將您的建議轉發給DevExtreme支持。感謝提示。 –

+0

只是一個側面說明:在我的項目之前,window.open在iOS 9上運行良好,自從最近的PhoneGap版本更新以來,它不再適用。 –

+0

我給了你3個選項,至少插件選項應該適合你的情況。當使用'canOpenURL'時會出現錯誤,也許以前版本的cordova沒有使用它並直接使用'openURL',在啓動失敗之前使用'openURL'會出現幾次(我認爲是50) 。或者,也許devexpress使用Xcode 6,在那裏你不需要做我告訴你的。要使用插件,請參閱https://www.devexpress.com/Support/Center/Question/Details/KA18816 – jcesarmobile

相關問題