Add the plug-in to the app
Create the Test application with
# create a new project folder and run the following command from it:
$ ionic start GahPluginTestApp blank
After the plug-in is created, it can be integrated into the Test application. Execute the following commands inside the generated Test application folder:
# add the plugin to created project
$ ionic cordova plugin add ../path/to/plugin
# add the platforms
$ ionic cordova platform add android@9.1.0
$ ionic cordova platform add ios
# add android permission plugin
$ ionic cordova plugin add cordova-plugin-android-permissions
$ npm install @ionic-native/android-permissions
# add androidx support
$ ionic cordova plugin add cordova-plugin-androidx
$ ionic cordova plugin add cordova-plugin-androidx-adapter
Note: this command should create the platforms folder inside the project directory. Due to an Ionic bug the folder maybe be generated elsewhere. In this case the folder needs to be created manually before running the command.
Edit src/app/home/home.page.html to add the buttons to request the runtime permission and to request the visit ID.
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>
Blank
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<div class="btn-wrapper">
<button ion-button full color="primary" (click)="getVisitId($event)">Get Visitor Id</button>
</div>
<div class="btn-wrapper">
<button ion-button full color="primary" (click)="requestPermissions()">Request Permissions</button>
</div>
</ion-content>
After that edit the corresponding TypeScript class src/app/home/home.page.ts
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
declare var GahPlugin: any;
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private androidPermissions: AndroidPermissions, private platform: Platform) {
// initialize gah plugin
this.platform.ready().then(()=> {
GahPlugin.initialize("https://demo-signal-collector.rnd.gemaltodigitalbankingidcloud.com/api/v1/tenants/mybank9/signals",
"2rj4semg",
"h-sdk.online-metrix.net", function(result) {
alert("Success: " + result);
// start prefetch of signals
GahPlugin.startPrefetch(function(result) {
console.log("Start prefetch: " + result);
}, function(error) {
console.log("Error: " + error);
});
}, function(error) {
alert("Error: " + error);
});
});
}
getVisitId(event) {
// check if signals are collected
GahPlugin.isSignalCollectionCompleted(function(result) {
// get visit id
GahPlugin.getVisiId(function(result) {
alert("Visit id: " + result);
// perform login etc. to bank backend
// if transaction is critical (high ammount transfer etc.) - set transaction as critical
// GahPlugin.setTransactionAsCritical(...)
// login(visitID)
// after operation perform clear transaction resources
// GahPlugin.clearTransaction(...)
}, function(error) {
alert("Error: " + error);
});
}, function(error) {
alert("Error: " + error);
});
}
requestPermissions() {
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.READ_PHONE_STATE).then(
result => {
console.log('Has permission?',result.hasPermission);
if (!result.hasPermission) {
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_PHONE_STATE);
}
}, err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_PHONE_STATE)
);
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.READ_PHONE_NUMBERS).then(
result => {
console.log('Has permission?',result.hasPermission);
if (!result.hasPermission) {
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_PHONE_NUMBERS);
}
}, err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.READ_PHONE_NUMBERS)
);
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION).then(
result => {
console.log('Has permission?',result.hasPermission);
if (!result.hasPermission) {
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION);
}
}, err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.ACCESS_FINE_LOCATION)
);
}
exitApplication() {
// before exit stop prefetch of signals
GahPlugin.stopPrefetch(function(result) {
console.log("Success: " + result);
}, function(error) {
console.log("Error: " + error);
});
}
}
And also update src/app/app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [AndroidPermissions, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule {}
After the source code is updated, the generated native Android and iOS projects must be updated from the root project folder.
# update android platform
$ ionic cordova prepare android
# update iOS platform
$ ionic cordova prepare ios
The generated native projects are located in platforms/android and platforms/ios. The projects can be built using the Ionic CLI, or by using Android Studio(gradle) and Xcode.
In Xcode Build Settings set:
- testability to false
- other linker flags: -ObjC -lc++ -all_load
# build android platform
$ ionic cordova build android
# build iOS platform
$ ionic cordova build ios
If the error "export 'DOCUMENT' was not found in '@angular/platform-browser'" occurs, fix the problem by referring to export-document-was-not-found-in-angular-platform-browser