Search code examples
iosionic-frameworkcordova-pluginsionic2file-transfer

Can't find variable: FileTransfer on IOS


I'm using the cordova's FileTransfer plugin with the ionic-native wrapper. The app runs successfully in iPhone simulator but when I run the app in my mobile device I get the error in the console as:

ORIGINAL EXCEPTION: ReferenceError: Can't find variable: FileTransfer with some stack trace.

Findings:

  • The app runs without any issue on Android devices
  • Reseting ionic state has no effect
  • Entering FileTransfer in console returns its object. So, it is clear that it has been initialized
  • The app runs good when all the reference to that plugin are removed from the app, even though there are other plugins(camera & datepicker). So, only the file-transfer plugin creates the problem.
  • Roughly 1 out of 10 times the app run in the device without any error but it crashes after restarting the app.

Plugins used

  • cordova-plugin-camera
  • cordova-plugin-datepicker
  • cordova-plugin-file-transfer
  • cordova-plugin-whitelist

Specifications:

  • Simulator iPhone6/iOS 9.3
  • Devices iPhone6/iOS 9.3.1 & iPhone4S/iOS 9.3.5
  • Cordova CLI: 6.2.0
  • Gulp version: CLI version 3.9.1
  • Gulp local: Local version 3.9.1
  • Ionic Framework Version: 2.0.0-beta.10
  • Ionic CLI Version: 2.0.0
  • Ionic App Lib Version: 2.0.0-beta.20
  • ios-deploy version: 1.8.6
  • ios-sim version: 5.0.8
  • OS: Mac OS X El Capitan
  • Node Version: v4.4.5
  • Xcode version: Xcode 7.3.1 Build version 7D1014

Code:

import {Injectable} from '@angular/core';
import {Transfer} from 'ionic-native';
@Injectable()
export class MyClass {
    fileTransfer = new Transfer();
    constructor(){
    }
    public upload (url: string, image: string, onProgress: any, opt?: any){
        let options = {
            fileKey: "file",
            mimeType: "image/png",
            chunkedMode: false
        }
        this.fileTransfer.onProgress(onProgress);
        return this.fileTransfer.upload(image, this.baseUrl + url, options);
    }
}

Solution

  • Uninstalling all the plugins and just running ionic run ios command fixed this issue. Since the ionic state reset also does the same thing, this might be a problem with the CLI.