Reputation: 565
I am using FileChooser ionic plugin for Android and FilePicker plugin for IOS. If I use the same code to build android and IOS app, it's giving me the error that FilePicker plugin cant be added to Android. To build app on different platforms currently, I am maintaining two different branches for iOS build and android build.
I want to maintain my code on only one branch. How can I do that?
Solutions which didn't work:
config.xml
Upvotes: 0
Views: 80
Reputation: 1046
You can add platform specific checks and use plugins accordingly.
import { Platform } from 'ionic-angular';
import { FileChooser } from '@ionic-native/file-chooser';
import { FilePath } from '@ionic-native/file-path';
import { IOSFilePicker } from '@ionic-native/file-picker';
constructor(
private fileChooser: FileChooser,
private filePicker: IOSFilePicker,
private filePath: FilePath,
private platform: Platform) {
}
chooseFile() {
if (this.platform.is('ios')) {
this.pickFileFromIOSDevice();
}
else if (this.platform.is('android')) {
this.pickFileFromAndroidDevice();
}
}
pickFileFromIOSDevice() {
this.filePicker.pickFile()
.then(
uri => {
this.fileName = uri.substring(uri.lastIndexOf("/") + 1);
}
)
.catch(error => {
this.showError(error);
});
}
pickFileFromAndroidDevice() {
this.fileChooser.open()
.then(
uri => {
this.filePath.resolveNativePath(uri)
.then(file => {
this.fileName = file.substring(file.lastIndexOf("/") + 1);
})
.catch(err => console.log(err));
}
)
.catch(error => {
this.showError(error);
});
}
Upvotes: 1