Does capacitor have a configuration similar to corodva ERRORURL? - capacitor

I tried to configure ERRORURL in capacitor, but it didn't work
"cordova":{
"preferences":{
"ErrorUrl":"error.html"
}
}

Related

Integrate Firebase Crashlytics in my Ionic App

So I wanted to integrate Firebase Crashlytics in my Ionic App. I followed the installation instructions outlined here. However I am a bit confused at the usage section of the documentation.
The documentation mentions this piece of code:
import { FirebaseCrashlytics } from '#ionic-native/firebase-crashlytics/ngx';
constructor(private firebaseCrashlytics: FirebaseCrashlytics) { }
...
const crashlytics = this.firebaseCrashlytics.initialize();
crashlytics.logException('my caught exception');
Where do I place this piece of code? Anywhere? Is the an example implementation available to look at? Any help will be much appreciated!
You can set it in "app.component" at start up:
constructor(..., private platform: Platform, private firebaseCrashlytics:
FirebaseCrashlytics, ...) {
super();
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
...
this.firebaseCrashlytics.initialise();
...
});
}
dont forget add to providers "FirebaseCrashlytics" in app.module.ts

Ionic 4 AdMob-Plus Ads

Has anyone got AdMob-Plus to work successfully with Ionic 4? Using the code below nothing shows up and the promise terminates with error without a message.
import { AdMob } from '#ionic-native/admob-plus/ngx';
constructor(
adMob: AdMob,
platform: Platform){
this.platform.ready()
this.adMob.setDevMode(true);
this.adMob.banner.show({
id: {
android: 'test',
ios: 'test',
}
})
}
I originally went with AdMob Free but didn't want to manually import the iOS SDK for AdMob. The current SDK version throws error ITMS-90809 when submitting to iOS app store.
***EDIT***
The comment below by Naga is the solution
some of native plugins will work just on android and ios and this is one of them.
this plugin will not work on pc even with build it on the browser.
so you have to test it on a native device or an emulator.
I just came across this issue today. The workaround is to just use the Cordova plugin as recommended here
Have you tried with cordova-admob plugin?
It has really great docs at https://ionic-admob.com
ionic plugin add cordova-admob
npm i #ionic-native/admob
You can use it like this:
import { Component, OnInit } from '#angular/core';
import { Platform } from 'ionic-angular';
import { Admob } from '#ionic-native/admob/ngx';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
})
export class HomePage implements OnInit {
constructor(private admob: Admob, private platform: Platform) { }
async ngOnInit() {
await this.platform.ready();
await this.admob.createBannerView({
bannerAdId: 'ca-app-pub-xxxx/xxxx',
});
}
}

ionic - back button exit app not working in Ionic 5

I am using Ionic version 5.4.16 and i am trying to close the app by hardware back button with a alert message for confirm to exit. I have checked a lot of tutorials for the same and everywhere i saw 2 ways to achieve that --
this.platform.exitApp();
and
navigator.app.exitapp()
and
navigator.["app"].exitapp();
But none of these option are working in Ionic 5, its not recognizing the function exitApp().
So how to achieve the same if anyone has faced the same issue do suggest, thank you.
To close the app, you must configure the following:
import { Plugins } from '#capacitor/core';
const { App } = Plugins;
App.exitApp();
Try to paste this code.
public unsubscribeBackEvent: any;
ionViewDidEnter() {
this.initializeBackButtonCustomHandler();
}
initializeBackButtonCustomHandler(): void {
this.unsubscribeBackEvent = this.platform.backButton.subscribeWithPriority(999999, () => {
if(window.confirm('Do you want to exit the app?'))
{
navigator['app'].exitApp();
}
});
}
ionViewWillLeave() {
this.unsubscribeBackEvent.unsubscribe();
}
I hope it's done.

Having issue with Battery status in Ionic 4

I'm using Ionic4 and I'm trying to get the device battery level. But I get an error:
ERROR TypeError: Invalid event target
and for the battery level, I get undefined.
Has anyone run into the same problem
There is an open bug report at ionic: https://github.com/ionic-team/ionic-native/issues/2972
Unfortunately no solution yet, however there is a workaround to bypass the ionic typescript wrapper and just listen directly on the window events.
fromEvent(window, 'batterystatus').subscribe((status) => {
console.log(status)
});
This is how I managed to get the battery status in Ionic 4:
window.addEventListener('batterystatus', this.onBatteryStatus, false);
onBatteryStatus(status) {
console.log('Level: ' + status.level + ' isPlugged: ' + status.isPlugged);
}
An easy way could be like this:
$ ionic cordova plugin add cordova-plugin-battery-status
$ npm install --save #ionic-native/battery-status#4
Then in your code:
import { Platform } from 'ionic-angular';
import { BatteryStatus } from '#ionic-native/battery-status';
batterylevel = 0;
constructor(...
private batteryStatus: BatteryStatus,
private plt: Platform ) {}
ionViewDidEnter()
{
// Cordova check
if(this.plt.is('core') || this.plt.is('mobileweb'))
{
// NO. It's a browser.
// don't call the batery.
}
else
{
const batterysubscription = this.batteryStatus.onChange().subscribe(status => {
this.batterylevel = status.level;
});
}
}
yourfunction()
{
console.log(this.batterylevel);
}
You'll also need to add it to your provider list too.
Of course, this will only work in emulation or a device.

How to integrate Anyline OCR SDK made for Cordova into Ionic2

I´m new to Ionic2, but experienced in web development. Just learning new platform at the moment.
So I have tried to integrate the Anyline OCR SDK
https://github.com/Anyline/anyline-ocr-cordova-module
but I am failing, it seems to me that the plugin is written in Javascript and not compatible with TS but I´m not sure...
Is there anyone out there that could help?
Thanks,
Ben
Not sure if you still need help with that, but for those out there who are looking for a working solution, here is mine:
1 - Add the Anyline Plugin to your project cordova plugin add io-anyline-cordova
2 - Create a new file ionic g provider anyline
3 - add this code to your anyline.ts file:
export class OCR {
constructor() {
if (anylineScan === undefined) {
var anylineScan = {};
}
}
anylineScan = {
onResult: function (result) {
console.log("MRZ result: " + JSON.stringify(result));
//do what you want here with the result
},
onError: function (error) {
console.log("scanning error");
},
scan: function () {
var licenseKey = "enterYourLicenceKeyHere";
try {
(<any>window).cordova.exec(this.onResult, this.onError, "AnylineSDK", "OCR", [licenseKey, {
"captureResolution":"1080p",
//your other config setting here
}]);
}
catch (e){
console.log("Cannot open scan view: ERROR occurred");
}
}
}
4 - Add the file references to your app.module.ts file
import { OCR } from '../yourFolderName/anyline';
...
providers: [Storage, OCR]
5 - In your page.ts file add the following call:
this.anyline.anylineScan.scan();
Important! It will not work in the browser, make sure you run ionic platform add ios (or android) and run the app on a device.
This should work!
Good luck and happy coding :-)