2017-11-11 240 views
0

我們正在開發使用Native File Transfer插件的應用程序。但由於一個奇怪的問題,我們無法爲iOS創建測試飛行/發佈版本。Ionic 2:嘗試訪問FileTransfer插件,但未安裝

問題: 即使我們看到下面的錯誤,而與

ionic cordova run ios -lc 

console.warn: Native: tried accessing the FileTransfer plugin but it's not installed. 

運行的應用程序在我們點擊一​​個按鈕調用fileTransfer.download(..)方法的「文件傳輸」插件安裝成功後 - 應用暫停執行而不拋出任何錯誤。

我創建了一個詳細的崗位原木和代碼爲:

https://github.com/ionic-team/ionic-native/issues/2110

任何幫助?

回答

2

徹底的頭腦風暴後,我找到了答案 -

我的問題是,文件傳輸對象可以從platform ready函數內部,但不是provider內訪問 - 這也對的iOS [Android版本工作正常]

這裏是我做過什麼:

因爲我需要providerFileTransfer的實例 - 我創建了一個變量 - 和更新方法 -

private fileTransfer: any; 

public setFileTransferRef(param){ 
    this.fileTransfer = param; 
} 

正如我可以訪問FileTransferplatform.ready()裏面 - 我實例化的FileTransferObject在那裏,並更新了provider如下 -

initializeApp() { 
    this.platform.ready().then(() => { 
     console.log('fileTransfer: '); 
     console.log(JSON.stringify(this.fileTransfer)); 
     // 
     let fileTransfer: FileTransferObject = this.fileTransfer.create(); 
     // 
     this.mediaIOSProv.setFileTransferRef(fileTransfer); 
     ..... 
     .... 
  • 哪裏mediaIOSProv提供負責下載郵編。

我也放在與cordova.js列入build/vendor.js後的index.html - (我碰到一些帖子,開發人員報告說,這樣做解決了他們失蹤的插件的問題) - 雖然沒有這樣的官方文檔

<body> 

    <!-- Ionic's root component and where the app will load --> 
    <ion-app></ion-app> 

    <!-- The polyfills js is generated during the build process --> 
    <script src="build/polyfills.js"></script> 

    <!-- The vendor js is generated during the build process 
     It contains all of the dependencies in node_modules --> 
    <script src="build/vendor.js"></script> 

    <!-- cordova.js required for cordova apps --> 
    <script src="cordova.js"></script> 

    <!-- The main bundle js is generated during the build process --> 
    <script src="build/main.js"></script> 

</body> 

由於應用程序成功運行iOS上 - 我不敢改變 安置cordova.js

我推測是 -

1:這將是最好的創建一個Provider來存儲在平臺內實例化的每個本機插件的引用 - 並在需要時使用引用

2:可能會丟失一些信息,尤其是關於iOS的,關於Ionic-Native Wrapper

任何建議/討論將不勝感激。