Commit 39b5d731 by Matteo

Cambiato plugin push notification

parent 924d6510
...@@ -12,15 +12,13 @@ dependencies { ...@@ -12,15 +12,13 @@ dependencies {
implementation project(':capacitor-app') implementation project(':capacitor-app')
implementation project(':capacitor-haptics') implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard') implementation project(':capacitor-keyboard')
implementation project(':capacitor-push-notifications')
implementation project(':capacitor-status-bar') implementation project(':capacitor-status-bar')
implementation "com.android.support:support-v4:27.+" implementation "com.android.support:support-v4:27.+"
implementation "com.android.support:support-v4:27.+" implementation "com.android.support:support-v4:27.+"
implementation "androidx.legacy:legacy-support-v4:1.0.0" implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "com.android.support:support-v13:27.+"
implementation "me.leolin:ShortcutBadger:1.1.17@aar"
implementation "com.google.firebase:firebase-messaging:17.0.+"
} }
apply from: "../../node_modules/phonegap-plugin-multidex/multidex.gradle"
if (hasProperty('postBuildExtras')) { if (hasProperty('postBuildExtras')) {
postBuildExtras() postBuildExtras()
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
"classpath": "com.capacitorjs.plugins.keyboard.KeyboardPlugin" "classpath": "com.capacitorjs.plugins.keyboard.KeyboardPlugin"
}, },
{ {
"pkg": "@capacitor/push-notifications",
"classpath": "com.capacitorjs.plugins.pushnotifications.PushNotificationsPlugin"
},
{
"pkg": "@capacitor/status-bar", "pkg": "@capacitor/status-bar",
"classpath": "com.capacitorjs.plugins.statusbar.StatusBarPlugin" "classpath": "com.capacitorjs.plugins.statusbar.StatusBarPlugin"
} }
......
...@@ -36,9 +36,5 @@ ...@@ -36,9 +36,5 @@
<param name="android-package" value="nl.xservices.plugins.SocialSharing"/> <param name="android-package" value="nl.xservices.plugins.SocialSharing"/>
</feature> </feature>
<feature name="PushNotification">
<param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/>
</feature>
</widget> </widget>
\ No newline at end of file
...@@ -11,5 +11,8 @@ project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/ ...@@ -11,5 +11,8 @@ project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/
include ':capacitor-keyboard' include ':capacitor-keyboard'
project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android') project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android')
include ':capacitor-push-notifications'
project(':capacitor-push-notifications').projectDir = new File('../node_modules/@capacitor/push-notifications/android')
include ':capacitor-status-bar' include ':capacitor-status-bar'
project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android') project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android')
...@@ -29,9 +29,5 @@ ...@@ -29,9 +29,5 @@
<param name="onload" value="true"/> <param name="onload" value="true"/>
</feature> </feature>
<feature name="PushNotification">
<param name="ios-package" value="PushPlugin"/>
</feature>
</widget> </widget>
\ No newline at end of file
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
"@capacitor/haptics": "1.1.0", "@capacitor/haptics": "1.1.0",
"@capacitor/ios": "3.2.4", "@capacitor/ios": "3.2.4",
"@capacitor/keyboard": "1.1.0", "@capacitor/keyboard": "1.1.0",
"@capacitor/push-notifications": "^1.0.6",
"@capacitor/status-bar": "1.0.3", "@capacitor/status-bar": "1.0.3",
"@ionic-native/android-permissions": "^5.36.0", "@ionic-native/android-permissions": "^5.36.0",
"@ionic-native/core": "^5.36.0", "@ionic-native/core": "^5.36.0",
...@@ -33,7 +34,6 @@ ...@@ -33,7 +34,6 @@
"@ionic-native/file": "^5.36.0", "@ionic-native/file": "^5.36.0",
"@ionic-native/file-opener": "^5.36.0", "@ionic-native/file-opener": "^5.36.0",
"@ionic-native/in-app-browser": "^5.36.0", "@ionic-native/in-app-browser": "^5.36.0",
"@ionic-native/push": "^5.36.0",
"@ionic-native/social-sharing": "^5.36.0", "@ionic-native/social-sharing": "^5.36.0",
"@ionic-native/splash-screen": "^5.36.0", "@ionic-native/splash-screen": "^5.36.0",
"@ionic-native/status-bar": "^5.36.0", "@ionic-native/status-bar": "^5.36.0",
...@@ -53,8 +53,6 @@ ...@@ -53,8 +53,6 @@
"es6-promise-plugin": "^4.2.2", "es6-promise-plugin": "^4.2.2",
"ionic-angular": "^3.9.10", "ionic-angular": "^3.9.10",
"jetifier": "^2.0.0", "jetifier": "^2.0.0",
"phonegap-plugin-multidex": "^1.0.0",
"phonegap-plugin-push": "^2.3.0",
"rxjs": "~6.6.0", "rxjs": "~6.6.0",
"rxjs-compat": "^6.6.7", "rxjs-compat": "^6.6.7",
"tslib": "^2.2.0", "tslib": "^2.2.0",
......
...@@ -31,7 +31,7 @@ export class AppComponent { ...@@ -31,7 +31,7 @@ export class AppComponent {
this.created = true; this.created = true;
} }
this.utilService.loadLingua(); this.utilService.loadLingua();
UtilService.isNotificaResume = true; if(UtilService.isNotificaResume == null) UtilService.isNotificaResume = false;
this.utilService.initConfig(false, 'notifiche'); this.utilService.initConfig(false, 'notifiche');
} }
......
...@@ -20,7 +20,7 @@ import { SocialSharing } from '@ionic-native/social-sharing/ngx'; ...@@ -20,7 +20,7 @@ import { SocialSharing } from '@ionic-native/social-sharing/ngx';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Push } from '@ionic-native/push/ngx'; //import { Push } from '@ionic-native/push/ngx';
import { IonicStorageModule } from '@ionic/storage-angular'; import { IonicStorageModule } from '@ionic/storage-angular';
export function createTranslateLoader(http: HttpClient) { export function createTranslateLoader(http: HttpClient) {
...@@ -55,7 +55,7 @@ export function createTranslateLoader(http: HttpClient) { ...@@ -55,7 +55,7 @@ export function createTranslateLoader(http: HttpClient) {
EmailComposer, EmailComposer,
InAppBrowser, InAppBrowser,
SocialSharing, SocialSharing,
Push, //Push,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy } { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
......
...@@ -370,6 +370,7 @@ export class IntervistePage implements OnInit { ...@@ -370,6 +370,7 @@ export class IntervistePage implements OnInit {
{ {
//this.utilService.showLoading(); //this.utilService.showLoading();
this.idCliente = AuthService.clienteSelezionato.id; this.idCliente = AuthService.clienteSelezionato.id;
if(this.idCliente == null) return;
if(fase == "initial") this.intervisteService.getListaTopics(AuthService.clienteSelezionato.id, null, null, false, null).subscribe((res: RichiesteResponse)=>{ if(fase == "initial") this.intervisteService.getListaTopics(AuthService.clienteSelezionato.id, null, null, false, null).subscribe((res: RichiesteResponse)=>{
if(res.error){ if(res.error){
this.utilService.presentAlert("Errore", "", res.error, ["OK"]); this.utilService.presentAlert("Errore", "", res.error, ["OK"]);
......
...@@ -249,6 +249,7 @@ export class NotifichePage implements OnInit { ...@@ -249,6 +249,7 @@ export class NotifichePage implements OnInit {
var titolo = null; var titolo = null;
//this.utilService.showLoading(); //this.utilService.showLoading();
AuthService.idReferente = await this.authService.getId(); AuthService.idReferente = await this.authService.getId();
if(AuthService.idReferente == null) return;
let referente = AuthService.idReferente; let referente = AuthService.idReferente;
if(this.titolo != null && this.titolo != "") titolo = this.titolo; if(this.titolo != null && this.titolo != "") titolo = this.titolo;
this.notificheService.getListaNotifiche(this.clienteSelezionato, referente, this.archiviati, titolo, this.tipoStruttura, this.strutturaSelezionata).subscribe((res: NotificheResponse)=>{ this.notificheService.getListaNotifiche(this.clienteSelezionato, referente, this.archiviati, titolo, this.tipoStruttura, this.strutturaSelezionata).subscribe((res: NotificheResponse)=>{
......
...@@ -184,6 +184,7 @@ export class ParerePage implements OnInit { ...@@ -184,6 +184,7 @@ export class ParerePage implements OnInit {
var titolo = null; var titolo = null;
this.utilService.showLoading(); this.utilService.showLoading();
this.idCliente = AuthService.clienteSelezionato.id; this.idCliente = AuthService.clienteSelezionato.id;
if(this.idCliente == null) return;
if(this.titolo != null && this.titolo != "") titolo = this.titolo; if(this.titolo != null && this.titolo != "") titolo = this.titolo;
if(fase == "initial") this.parereService.getListaPareri(this.idCliente, this.archiviati, titolo).subscribe((res: RichiesteResponse)=>{ if(fase == "initial") this.parereService.getListaPareri(this.idCliente, this.archiviati, titolo).subscribe((res: RichiesteResponse)=>{
this.utilService.closeLoading(); this.utilService.closeLoading();
......
...@@ -34,12 +34,11 @@ export class PreviewHomePage implements OnInit { ...@@ -34,12 +34,11 @@ export class PreviewHomePage implements OnInit {
if(EventsService.updateStrutture) if(EventsService.updateStrutture)
{ {
this.setStrutture(); this.setStrutture();
if(this.startup) if(UtilService.redirectToNotifiche)
if(UtilService.redirectToNotifiche) {
{ UtilService.redirectToNotifiche = false;
UtilService.redirectToNotifiche = false; this.utilService.apriPagina("notifiche");
this.utilService.apriPagina("notifiche"); }
}
} }
setTimeout(() => { setTimeout(() => {
this.eventsIdle(); this.eventsIdle();
...@@ -51,7 +50,6 @@ export class PreviewHomePage implements OnInit { ...@@ -51,7 +50,6 @@ export class PreviewHomePage implements OnInit {
realEstateBrokerage: Struttura; realEstateBrokerage: Struttura;
name: String; name: String;
pageReady: boolean = false; pageReady: boolean = false;
startup: boolean = true;
setStrutture() setStrutture()
{ {
......
...@@ -12,7 +12,8 @@ import { Struttura } from '../interface/struttura'; ...@@ -12,7 +12,8 @@ import { Struttura } from '../interface/struttura';
import { ParereResponse } from '../interface/parere-response'; import { ParereResponse } from '../interface/parere-response';
import { catchError, tap } from 'rxjs/operators'; import { catchError, tap } from 'rxjs/operators';
import { HttpClientDataService } from './http-client-data.service'; import { HttpClientDataService } from './http-client-data.service';
import { PushObject, PushOptions, Push } from '@ionic-native/push/ngx'; //import { PushObject, PushOptions, Push } from '@ionic-native/push/ngx';
import { ActionPerformed, PushNotificationSchema, PushNotifications, Token } from '@capacitor/push-notifications';
import { ErrorResponse } from '../auth/interface/error-response'; import { ErrorResponse } from '../auth/interface/error-response';
import { SplashScreen } from '@ionic-native/splash-screen/ngx'; import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { AndroidPermissions } from '@ionic-native/android-permissions/ngx'; import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
...@@ -47,7 +48,7 @@ export class UtilService { ...@@ -47,7 +48,7 @@ export class UtilService {
private storage: Storage, private storage: Storage,
public translate: TranslateService, public translate: TranslateService,
private httpClientDataService: HttpClientDataService, private httpClientDataService: HttpClientDataService,
public push: Push, //public push: Push,
private splashScreen: SplashScreen, private splashScreen: SplashScreen,
private statusBar: StatusBar, private statusBar: StatusBar,
private androidPermissions: AndroidPermissions, private androidPermissions: AndroidPermissions,
...@@ -591,7 +592,17 @@ export class UtilService { ...@@ -591,7 +592,17 @@ export class UtilService {
pushNotification(idReferente) pushNotification(idReferente)
{ {
if(this.platform.is("desktop")) return; if(this.platform.is("desktop")) return;
this.push.hasPermission() PushNotifications.requestPermissions().then(result => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
this.continuePush(idReferente);
} else {
this.presentAlert("Errore", "", "Non hai il permesso di accedere alle push notification", ["OK"]);
console.log('We do not have permission to send push notifications');
}
});
/*this.push.hasPermission()
.then((res: any) => { .then((res: any) => {
if (res.isEnabled || this.platform.is("ios")) { if (res.isEnabled || this.platform.is("ios")) {
...@@ -601,21 +612,13 @@ export class UtilService { ...@@ -601,21 +612,13 @@ export class UtilService {
console.log('We do not have permission to send push notifications'); console.log('We do not have permission to send push notifications');
} }
}); });*/
} }
continuePush(idReferente) continuePush(idReferente)
{ {
/*this.push.createChannel({ /*const options: PushOptions = {
id: "it.aimconsulting.leonardomannelli",
description: "Canale",
// The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
importance: 3
});*/
const options: PushOptions = {
android: { android: {
//senderID:''
}, },
ios: { ios: {
alert: 'true', alert: 'true',
...@@ -632,25 +635,46 @@ export class UtilService { ...@@ -632,25 +635,46 @@ export class UtilService {
this.savePushRegistrationId(registration.registrationId, idReferente); this.savePushRegistrationId(registration.registrationId, idReferente);
}); });
} }
);*/
PushNotifications.addListener('registration',
(token: Token) => {
this.getPushRegistrationId().then(id => {
this.savePushRegistrationId(token.value, idReferente);
});
}
);
PushNotifications.addListener('pushNotificationReceived',
(notification: PushNotificationSchema) => {
this.presentAlert(notification.title, "", notification.body, ["OK"]);
}
);
PushNotifications.addListener('pushNotificationActionPerformed',
(notification: ActionPerformed) => {
UtilService.isNotificaResume = true;
//this.presentAlert(notification.notification.title+ " coldstart", "", notification.notification.body, ["OK"]);
this.initConfig(true, "notifiche");
}
); );
pushObject.on('notification').subscribe((data: any) =>{ /*pushObject.on('notification').subscribe((data: any) =>{
/*console.log(data.message);
console.log(data.title);
console.log(data.count);
console.log(data.sound);
console.log(data.image);
console.log(data.additionalData);*/
if(data.additionalData.coldstart){ if(data.additionalData.coldstart){
this.presentAlert(data.title+ " coldstart", "", data.message, ["OK"]); this.presentAlert(data.title+ " coldstart", "", data.message, ["OK"]);
this.initConfig(true, "notifiche"); this.initConfig(true, "notifiche");
} }
else this.presentAlert(data.title, "", data.message, ["OK"]); else this.presentAlert(data.title, "", data.message, ["OK"]);
}); });*/
pushObject.on('error').subscribe((error: any) =>{ /*pushObject.on('error').subscribe((error: any) =>{
console.log("Errore durante le notifiche: "+error); console.log("Errore durante le notifiche: "+error);
}); });*/
PushNotifications.addListener('registrationError',
(error: any) => {
console.log("Errore durante le notifiche: "+error);
}
);
} }
savePushRegistrationId(id:string, idReferente) savePushRegistrationId(id:string, idReferente)
...@@ -723,7 +747,6 @@ export class UtilService { ...@@ -723,7 +747,6 @@ export class UtilService {
this.onResumeSubscription this.onResumeSubscription
console.log('resumed'); console.log('resumed');
this.firstPause = true; this.firstPause = true;
UtilService.isNotificaResume = false;
} }
}); });
} }
...@@ -793,7 +816,8 @@ export class UtilService { ...@@ -793,7 +816,8 @@ export class UtilService {
} }
async redirectToFirstPage(nextPage) { async redirectToFirstPage(nextPage) {
var idReferente = await this.getIdUser(); var idReferente = null;
while(idReferente == null) idReferente = await this.getIdUser();
AuthService.isClienteLoggato = await this.getIsCliente(); AuthService.isClienteLoggato = await this.getIsCliente();
if(AuthService.isClienteLoggato) this.apriPagina(nextPage); if(AuthService.isClienteLoggato) this.apriPagina(nextPage);
else else
...@@ -804,12 +828,13 @@ export class UtilService { ...@@ -804,12 +828,13 @@ export class UtilService {
} }
else else
{ {
if(res.autorizzato && !this.startup && UtilService.isNotificaResume) this.apriPagina(nextPage); if(res.autorizzato && !this.startup && UtilService.isNotificaResume)
{
EventsService.setUpdateStrutture();
UtilService.redirectToNotifiche = true;
this.apriPagina(nextPage);
}
else{ else{
if(!UtilService.isNotificaResume){
UtilService.isNotificaResume = true;
return;
}
if(res.autorizzato && this.startup && this.primaRestart) if(res.autorizzato && this.startup && this.primaRestart)
{ {
this.primaRestart = false; this.primaRestart = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment