Local file reader for cordova windows project - windows

Is it possible to read files (pdf,...) from my cordova windows app folder ?
I already use FileOpener to read local files in Android Tablets but this plugin is developed for Android use.
Can someone help me please ?

Use cordova-plugin-file-opener2. It supports for windows phone too.
Add this from Command line:
cordova plugin add https://github.com/pwlin/cordova-plugin-file-opener2
Then use this JS lines for opening a pdf file with default app
cordova.plugins.fileOpener2.open(
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
This plug in is working fine in windows phone 8.

Related

Authentication problem with running ionic app using firebase on native device, everything works fine with live reload

Good morning!
I have a strange problem where i can run & authenticate my user on my ios device perfectly fine running the app using the command below.
ionic capacitor run -l --external
Using an emulator, it works sometimes, though not always.
When I try to deploy the app using Xcode, the app opens and looks normal, but if I try to send authentication requests to firebase, the app just keeps on loading, although the requests are successfully performed.
I first thought the problem was because of using LocalStorage so I rebuilt everything using Ionic Storage. But that didn't help.
I tried different versions of adding the Firebase SDK in Swift or in the Cocoa Pods file but the behaviour doesn't change so I don't believe that this is a issue with a wrong firebase configuration, what is the proper way to do this by the way - or is Ionic doing this for me already?
The output of Xcode doesn't provide any valuable information either.
2021-12-01 11:20:13.990875+0100 App[3162:27661] Writing analzed variants.
2021-12-01 11:20:14.125754+0100 App[3162:27661] KeyboardPlugin: resize mode - native
⚡️ Loading app at capacitor://localhost...
2021-12-01 11:20:14.552490+0100 App[3162:27661] Writing analzed variants.
⚡️ WebView loaded
⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
⚡️ [log] - null
⚡️ To Native -> App addListener 60635511
2021-12-01 11:20:21.393141+0100 App[3162:27661] [Accessibility] WKContentView[#] set up: # pid: # MACH_PORT -830404096
login-function
loginWithEmail() {
let email: string = this.loginForm.get("email").value;
let password: string = this.loginForm.get("password").value;
this.loadingService.present({
message: "Logging in . . ."
});
this.authService
.loginWithEmail(email, password)
.then((result) => {
this.authService.SetUserData(result.user)
this.resetLoginForm();
this.loginSuccess();
this.router.navigateByUrl("/tabs/intensity");
})
.catch(error => {
console.log(error);
this.loginFailed(error);
});
}
login-success
loginSuccess() {
this.loadingService.dismiss();
this.toastService.present({
message: "Welcome back!",
duration: 3000,
color: "secondary"
});
}
login-with-email
import { AngularFireAuth } from "#angular/fire/compat/auth";
...
async loginWithEmail(email: string, password: string) {
return await this.afAuth.signInWithEmailAndPassword(email, password);
}
set user-data function
SetUserData(user) {
this.user = user;
const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.uid}`);
const userData: User = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL,
emailVerified: user.emailVerified
}
return userRef.set(userData, {
merge: true
})
}
Running it multiple times some times I get this error.
API error: <_UIKBCompatInputView: 0x7fb965726040; frame = (0 0; 0 0); layer = <CALayer: 0x600002f718a0>> returned 0 width, assuming UIViewNoIntrinsicMetric
I am really stuck on this and would appreciate any help. Thank you & kind regards.
Ionic 6.18.1
Angular 12.1.5
Xcode Version 13.1 (13A1030d)

Firebase messaging issue when app is in foreground on Ionic 5 app

I am following the firebase docs for implementation of Cloud Messgaing.
Receiving and handling messages while my ionic app is in the background works fine but when handling same in foreground I am running into issues.
This is the code:
PushNotifications.addListener('pushNotificationReceived',
(notification : PushNotificationSchema) => {
alert("Push received while app open: " + JSON.stringify(notification));
const title = notification.notification.title;
const body = notification.notification.body;
const page = notification.notification.data.department;
alert ("Notification: department = " + page + " Title : " + title);
//console.log("NOTIFICATION REC IN APP FOREGROUND: " + title + " AND BODY : " + body);
if (page){
this.router.navigate(['/'+page]);
}
},
);
The first alert with details of the notification executes every time, but nothing after.
In the Xcode console I see an error but there is no description:
Any idea what the issue might be with my ionic code or how to determine the error thrown in Xcode would be appreciated.
Hope this is helpful for some as I found there are allot of potential answers out there but the only solution I found is as follows:
Add this to the capacitor.config.json of your Ionic project:
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
}
Then build / synch your ionic app:
ionic build
ionic cap sync
See Capacitor Docs here for more details.

nativescript: how to add extension while using Downloader plugin

Hello i need to download an audio file from an external URL and it works but without the .mp3 extension, which is required for the player to recognize it, here is my code:
getAudio(token:String,interestPointId:string,link:string, audioId):string{
const downloadManager = new Downloader();
var path:string;
const imageDownloaderId = downloadManager.createDownload({
url:link
});
downloadManager
.start(imageDownloaderId, (progressData: ProgressEventData) => {
console.log(`Progress : ${progressData.value}%`);
console.log(`Current Size : ${progressData.currentSize}%`);
console.log(`Total Size : ${progressData.totalSize}%`);
console.log(`Download Speed in bytes : ${progressData.speed}%`);
})
.then((completed: DownloadEventData) => {
path=completed.path;
console.log(`Image : ${completed.path}`);
})
.catch(error => {
console.log(error.message);
});
return path;
}
is just a modified version from the example (https://market.nativescript.org/plugins/nativescript-downloader)
the goal is to download the file and get the path to it while the name should be something like ~path/idAudio.mp3
any help is welcome, thanks in advance!
You can set the fileName and the path on the createDownload it is not documented (I forgot) there is interface you can use so what you need to is the following also i would recommend you not try to save the file to the project root e.g ~/blah/blah.mp3 that would fail on a real ios device
downloadManager.createDownload({
url:link
path:somePath,
fileName: 'idAudio.mp3'
}

Phonegap 3 - LocalFileSystem not defined

I used this code in phonegap 2.6.0 and it worked, now I upgraded to phonegap 3.0.0 and xcode 5 and I get this error:
onDeviceReady: =>
try
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, failFS)
catch e
alert(e)
**ReferenceError: LocalFileSystem is not defined**
I get the same error in Chrome, and that I guess is normal?
The documentation is still the same from 2.6 to 3, so Im not sure what happend!
I solved the problem adding cordova.js file to platforms/ios/www/
You should add File plugin to your app using:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
You may want to check this:
http://docs.phonegap.com/en/edge/cordova_file_file.md.html#File
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function gotFS(fileSystem) {
console.log("got filesystem");
console.log(fileSystem.root.fullPath);
}
function fail() {
console.log("failed to get filesystem");
}

phonegap build and pushwoosh gets error aps environment not found?

I´m trying to get the pushwoosh plugin to work in a phonegap build app and all I get is an alert error that the aps environment is not found.
This is the steps I took.
Created a new appID that I enabled push notification on.
Created a new APNs Development Certificate. And downloaded it.
Created a new mobile provisioning profile and downloaded it and installed it on my phone.
Checked the mobile provisioning profile that it had "aps-environment" and "developer" in it.
In key chain I rightclicked the aps certificate and exported a .cer and a .p12 file and uploaded them to my newly created application on pushwoosh.com
I wrote the pushwoosh application id in my index file and the right id in the config file(same as in my mobile provisioning file)
I rightclicked my iPhone Developer Certificate in key chain and exported a .p12 file for phonegap and called it mypushapp.p12.
I created a new key at phonegap build and uploaded the mypushapp.p12 and the mobile provising file and then I build my app.
The app itself works as it should, but I get this aps error that it failed to register?
In my index file I init pushwoosh in the deviceready function and this is the pushwooshcode that I have.
function initPushwoosh() {
alert("init pushwoosh");
var pushNotification = window.plugins.pushNotification;
pushNotification.onDeviceReady();
pushNotification.registerDevice({alert:true, badge:true, sound:true, pw_appid:"5FB5C-E3F1F", appname:"newpushtest"},
function(status) {
var deviceToken = status['deviceToken'];
console.warn('registerDevice: ' + deviceToken);
},
function(status) {
console.warn('failed to register : ' + JSON.stringify(status));
navigator.notification.alert(JSON.stringify(['failed to register ', status]));
});
pushNotification.setApplicationIconBadgeNumber(0);
pushNotification.getTags(function(tags) {
console.warn('tags for the device: ' + JSON.stringify(tags));
},
function(error) {
console.warn('get tags error: ' + JSON.stringify(error));
});
//start geo tracking. PWTrackSignificantLocationChanges - Uses GPS in foreground, Cell Triangulation in background.
pushNotification.startLocationTracking('PWTrackSignificantLocationChanges',
function() {
console.warn('Location Tracking Started');
});
document.addEventListener('push-notification', function(event) {
var notification = event.notification;
navigator.notification.alert(notification.aps.alert);
//to view full push payload
//navigator.notification.alert(JSON.stringify(notification));
pushNotification.setApplicationIconBadgeNumber(0);
});
}
I don´t know where I go wrong so any input appreciated thanks.

Resources