Я сталкиваюсь с некоторыми проблемами при разработке простого приложения с подключаемым модулем геозон для Ionic 3. Это приложение должно выдавать уведомление, когда пользователь входит в забор, но когда пользователь нажимает на уведомление, уведомление должно открывать страницуотличается от корневой страницы.Я пытался подписать метод onNotificationClicked () плагина геозон, но он не работал.
Это код
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Geofence } from '@ionic-native/geofence';
import { Page2Page } from '../../pages/page2/page2';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController,
private geofence: Geofence) {
geofence.initialize().then(
// resolved promise does not return a value
() =>
console.log('Geofence Plugin Ready'),
(err) => console.log(err)
)
}
ionViewDidLoad(){
this.addGeofence();
this.geofence.onNotificationClicked().subscribe(()=>{
this.navCtrl.push(Page2Page);
});
}
private addGeofence() {
//options describing geofence
let fence = {
id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', //any unique ID
//nonna 44.921575, 9.970478
latitude: 44.921575, //center of geofence radius
longitude: 9.970478,
radius: 100, //radius to edge of geofence in meters
transitionType: 3, //see 'Transition Types' below
notification: { //notification settings
id: 1, //any unique ID
title: 'You crossed a fence', //notification title
text: 'You just arrived to pos1.', //notification body
openAppOnClick: true //open app when notification is tapped
}
}
let fence2 = { //44.929907, 9.900818
id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb1', //any unique ID
//nonna 44.921575, 9.970478
latitude: 44.929907, //center of geofence radius
longitude: 9.900818,
radius: 100, //radius to edge of geofence in meters
transitionType: 3, //see 'Transition Types' below
notification: { //notification settings
id: 2, //any unique ID
title: 'You crossed a fence', //notification title
text: 'You just arrived to pos2.', //notification body
openAppOnClick: true //open app when notification is tapped
}
}
let fence3 = { //44.896738, 9.965208
id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb2', //any unique ID
//nonna 44.921575, 9.970478
latitude: 44.896738, //center of geofence radius
longitude: 9.965208,
radius: 100, //radius to edge of geofence in meters
transitionType: 3, //see 'Transition Types' below
notification: { //notification settings
id: 3, //any unique ID
title: 'You crossed a fence', //notification title
text: 'You just arrived to pos3.', //notification body
openAppOnClick: true //open app when notification is tapped
}
}
this.geofence.addOrUpdate([fence, fence2, fence3]).then(
() => console.log('Geofence added'),
(err) => console.log('Geofence failed to add')
);
}
}
В документации я нашел эту строку кода, ноЯ не понимаю, как его использовать, кто-нибудь может объяснить мне, как это работает?
window.geofence.onNotificationClicked = function (notificationData) {
console.log('App opened from Geo Notification!', notificationData);
};