Ionic file opener - ionic2

I am developing an app for android, ios and windows. One of the requirements is being able to download a pdf that is stored in the assets folder in the ionic app. I am using this plugin https://ionicframework.com/docs/native/file-opener/. I am executing this code as per the documentation.
this.fileOpener.open(‘assets/pdf-test.pdf’, ‘application/pdf’)
.then(() => console.log(‘File is opened’))
.catch(e => console.log(‘Error openening file’, e));
However I get the following error
“file not found”
Please help

assetsfolder only works in your app. What you are telling these others apps to do is to read help_doc.pdf out of their assets, and they do not have such a file.
try this code , but if not work , some time browser not support open pdf , then go must go with plugin fileOpener2
var location = cordova.file.applicationDirectory +"www/assets/MobiMedPrivacyPolicy.pdf";
window.resolveLocalFileSystemURL(location, function(fileEntry) {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory + '/Download/', function(dirEntry) {
fileEntry.copyTo(dirEntry, "MobiMedPrivacyPolicy.pdf", function(newFileEntry) {
window.open(newFileEntry.nativeURL, '_blank', 'location=no');
});
});
},function(error)
{
console.log(error)
});

Related

Expo Image Picker vs RN-image picker

I am quite new to RN . I know this question is being repeated but I didn't quite get ans I was looking for there .
So my current project uses
expo for web and react-native cli for the android set up .
I want to add an image-picker to the project.
I see two options at my side .
RN-image-picker
expo-image-picker
I have some issues and some questions !!
Is RN-native-image picker comaptible with web ??
I think its not ,there are two resons I think that ,this lib uses Nativemodules, which
won't be bundled for web and its giving undefined error for NativeModules when I run with
web while it works fine on android .
Should I use expo-image-picker when I am creating a android build with react-native cli ??
The build doesn't give errors and it shouldn't ,but when I click on upload image ,app
crashes after I select image.I read the docs and github for the issue.Many people pointed
out its ram allocation issue,which can be sorted with disbaling "Dont keep activities" in
developer's option,which I haven't tried yet .
Also on web ,the following code snippet returns base64 as uri,is it default behaviour ??
I am using this code snippet for expo-image-picker,which ends up crashing app when I build app with rn cli,but doesn't seem to cause issues with expocli build.But I want to use expo for web and rn for android.
Also on web ,the following code snippet returns base64 as uri,is it default behaviour ??
const pickImage = async () => {
try{
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
base64:false
})
if(!result.isCancelled)return result.uri ;
}catch(err){
console.log(err) ;
}
}
So what should I do in this case,use expo-image-picker as it seems to be compatible with all platforms/both ?
Any kind of input would be helpful !!
I'm not a fan of Expo, and I don't have experience with that but I try to answer to your question that can be.
Is RN-native-image picker comaptible with web ??
You have right, the library supports only mobile devices.
Should I use expo-image-picker when I am creating an android build with react-native cli ??
From expo documentation, I read that but I know also that sometimes the rn-cli and expo has some package differences, and this answer proves that.
Expo never locks you in, you can "eject" at any time and your project will just be a typical native project with the React Native and Expo SDK packages that your app is using installed and configured.
I don't know what the exception, and maybe the solution that you put in your answer work well, but maybe is possible to have some dependency mismecc? Such as a none object on the Web app? or something like that.
Also on web ,the following code snippet returns base64 as uri,is it default behaviour ??
This looks like be an bug and this issue on github maybe can confirm my idea

errorCode : MINIMUM_SERVER when access obtainAccessToken in IBM MFP8

I'm getting failure when trying to call
WLAuthorizationManager.obtainAccessToken()
Using Ionic 2 and MFP 8
This is the message
============== {"status":-1,"responseText":"","errorMsg":"This version of the MobileFirst client SDK requires a minimal server version
greater than IFIX
8.0.0.0-IF201701250919","errorCode":"MINIMUM_SERVER"}
Our installation team installed the latest iFix pack also.
I'm attaching the code snippet also.
app.component.ts
WL.Client.pinTrustedCertificatePublicKey('mycert.cer').then(() => {
console.log('--------SSL Pin Success-------------');
WLAuthorizationManager.obtainAccessToken().then((accessToken) => {
console.log('--------accessToken Success-------------', accessToken);
}, (response) => {
console.log('--------accessToken Failure-------------', response);
let usrname ="roney";
let passwrd = "roney#123";
let modalc = this.modal.create("UserLoginChallengeHandler",{"username":usrname,"password":passwrd});
modalc.present();
modalc.onDidDismiss((data)=>{
//further to proceed goes here
this.statusBar.styleDefault();
this.splashScreen.hide();
this.fcmInformation();
});
});
}).fail((error) => {
console.log('--------SSL Pin failed-------------', error);
});
This means, your server is still running an iFix level that is older than the client. It is possible the server is still not updated - may be the update wasn't proper or complete. Server side log ( tracing) will tell exactly what versions of server side components are running.
Another option is to verify the network capture - this will give more details on the server side message and version.

Ionic2 InAppBrowser

Hi I want to put a button in my page when clicked it will launch the website of the given item. However I got a problem and I don't know how to fix it. I just followed a recent tutorial online but unfortunately it didn't worked for me.
1.) This is the error appearing when I click on the button, circled in the image.
2.) Declaration of the constructor in the js file
3.) html button
4.) App version
Add
import {InAppBrowser} from 'ionic-native';
Also I did not see this in your .js file
launch(url) {
this.platform.ready().then(() => {
open(url, "_blank", "location=no");
});
}
This is required.
Add
cordova plugin add cordova-inappbrowser
In your ts file just add this line under your imports and above your #component
declare var cordova ;
Once the platform is ready just add the below lines.
cordova.InAppBrowser.open(url, '_blank', 'location=yes')
Here is the example explained as how to open a browser in ionic-2.
https://www.thepolyglotdeveloper.com/2016/01/launch-websites-with-ionic-2-using-the-inappbrowser/

How Gulp + sourcemaps work for debugging

So I just got set up with Gulp yesterday and after a rocky start I'm well on my way to automating build processes, but I decided to try and do something a teensy bit trickier and suddenly hit another wall.
My desired output is to have a minified javascript file which I can serve to the browser and, upon inspecting in Chrome or Firefox, see the original source code. Pretty simple, right?
I currently have the following in my gulpfile:
gulp.task('minify', function() {
gulp.src('./sources/**/*.js')
.pipe(sourcemaps.init())
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
}
}))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('./www/js'));
});
This successfully generates the sourcemaps in ./www/js/maps/ and it puts the following at the bottom of the uncompressed files:
//# sourceMappingURL=maps/<whatever>.js.map
However it does not append such a comment to the bottom of the compressed files. As such when I open these files in a browser it's unable to show me the original source.
What am I doing wrong?
You can try this:
gulp.task('minify', function() {
gulp.src('./sources/**/*.js')
.pipe(sourcemaps.init())
.pipe(minify({
ext:{
src:'.js',
min:'.min.js'
}
}))
.pipe(sourcemaps.write('maps', {
addComment: true
}))
.pipe(gulp.dest('./www/js'));
});

CaptureError.CAPTURE_INTERNAL_ERR on Android trying to use capture.captureImage

I am trying to write a hybrid app for Android using VS 2013 update 3 and the multi-device hybrid app extension (Cordova v3.5.0). Everything is working well except the Media Capture plugin. I am calling navigator.device.capture.captureImage(MediaCaptureSuccess, MediaCaptureError, { limit: 3 }) which opens up the camera app. I can take a picture but when I click Ok on the device, my error callback is executed with CaptureError.CAPTURE_INTERNAL_ERR with no other information. I have tried switching to org.apache.cordova.media-capture#0.3.4 (currently using 0.3.1) but when I try to compile, I get a plugman error when it tries to retrieve it. I have searched the debug output for clues and the only thing that I found was the following line "Unknown permission android.permission.RECORD_VIDEO in package..." but that seems to be a valid user permission. When I look at capture.java generated by the build, I can see that this error is returned if there is an IOException occurs.
Does anyone have any suggestions on how to fix this or what to check next?
Try this plugin
Config:
<vs:feature>org.apache.cordova.camera#0.3.0</vs:feature>
JS:
navigator.camera.getPicture(onSuccess, onFail, {
quality: 30,
destinationType: Camera.DestinationType.FILE_URI,
saveToPhotoAlbum: true
});