Commit 39b5d731 by Matteo

Cambiato plugin push notification

parent 924d6510
......@@ -12,15 +12,13 @@ dependencies {
implementation project(':capacitor-app')
implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-push-notifications')
implementation project(':capacitor-status-bar')
implementation "com.android.support:support-v4:27.+"
implementation "com.android.support:support-v4:27.+"
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')) {
postBuildExtras()
......
......@@ -12,6 +12,10 @@
"classpath": "com.capacitorjs.plugins.keyboard.KeyboardPlugin"
},
{
"pkg": "@capacitor/push-notifications",
"classpath": "com.capacitorjs.plugins.pushnotifications.PushNotificationsPlugin"
},
{
"pkg": "@capacitor/status-bar",
"classpath": "com.capacitorjs.plugins.statusbar.StatusBarPlugin"
}
......
......@@ -36,9 +36,5 @@
<param name="android-package" value="nl.xservices.plugins.SocialSharing"/>
</feature>
<feature name="PushNotification">
<param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/>
</feature>
</widget>
\ No newline at end of file
......@@ -11,5 +11,8 @@ project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/
include ':capacitor-keyboard'
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'
project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android')
......@@ -29,9 +29,5 @@
<param name="onload" value="true"/>
</feature>
<feature name="PushNotification">
<param name="ios-package" value="PushPlugin"/>
</feature>
</widget>
\ No newline at end of file
......@@ -25,6 +25,7 @@
"@capacitor/haptics": "1.1.0",
"@capacitor/ios": "3.2.4",
"@capacitor/keyboard": "1.1.0",
"@capacitor/push-notifications": "^1.0.6",
"@capacitor/status-bar": "1.0.3",
"@ionic-native/android-permissions": "^5.36.0",
"@ionic-native/core": "^5.36.0",
......@@ -33,7 +34,6 @@
"@ionic-native/file": "^5.36.0",
"@ionic-native/file-opener": "^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/splash-screen": "^5.36.0",
"@ionic-native/status-bar": "^5.36.0",
......@@ -53,8 +53,6 @@
"es6-promise-plugin": "^4.2.2",
"ionic-angular": "^3.9.10",
"jetifier": "^2.0.0",
"phonegap-plugin-multidex": "^1.0.0",
"phonegap-plugin-push": "^2.3.0",
"rxjs": "~6.6.0",
"rxjs-compat": "^6.6.7",
"tslib": "^2.2.0",
......
......@@ -31,7 +31,7 @@ export class AppComponent {
this.created = true;
}
this.utilService.loadLingua();
UtilService.isNotificaResume = true;
if(UtilService.isNotificaResume == null) UtilService.isNotificaResume = false;
this.utilService.initConfig(false, 'notifiche');
}
......
......@@ -20,7 +20,7 @@ import { SocialSharing } from '@ionic-native/social-sharing/ngx';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
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';
export function createTranslateLoader(http: HttpClient) {
......@@ -55,7 +55,7 @@ export function createTranslateLoader(http: HttpClient) {
EmailComposer,
InAppBrowser,
SocialSharing,
Push,
//Push,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
......
......@@ -370,6 +370,7 @@ export class IntervistePage implements OnInit {
{
//this.utilService.showLoading();
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(res.error){
this.utilService.presentAlert("Errore", "", res.error, ["OK"]);
......
......@@ -249,6 +249,7 @@ export class NotifichePage implements OnInit {
var titolo = null;
//this.utilService.showLoading();
AuthService.idReferente = await this.authService.getId();
if(AuthService.idReferente == null) return;
let referente = AuthService.idReferente;
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)=>{
......
......@@ -184,6 +184,7 @@ export class ParerePage implements OnInit {
var titolo = null;
this.utilService.showLoading();
this.idCliente = AuthService.clienteSelezionato.id;
if(this.idCliente == null) return;
if(this.titolo != null && this.titolo != "") titolo = this.titolo;
if(fase == "initial") this.parereService.getListaPareri(this.idCliente, this.archiviati, titolo).subscribe((res: RichiesteResponse)=>{
this.utilService.closeLoading();
......
......@@ -34,12 +34,11 @@ export class PreviewHomePage implements OnInit {
if(EventsService.updateStrutture)
{
this.setStrutture();
if(this.startup)
if(UtilService.redirectToNotifiche)
{
UtilService.redirectToNotifiche = false;
this.utilService.apriPagina("notifiche");
}
if(UtilService.redirectToNotifiche)
{
UtilService.redirectToNotifiche = false;
this.utilService.apriPagina("notifiche");
}
}
setTimeout(() => {
this.eventsIdle();
......@@ -51,7 +50,6 @@ export class PreviewHomePage implements OnInit {
realEstateBrokerage: Struttura;
name: String;
pageReady: boolean = false;
startup: boolean = true;
setStrutture()
{
......
......@@ -12,7 +12,8 @@ import { Struttura } from '../interface/struttura';
import { ParereResponse } from '../interface/parere-response';
import { catchError, tap } from 'rxjs/operators';
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 { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
......@@ -47,7 +48,7 @@ export class UtilService {
private storage: Storage,
public translate: TranslateService,
private httpClientDataService: HttpClientDataService,
public push: Push,
//public push: Push,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private androidPermissions: AndroidPermissions,
......@@ -591,7 +592,17 @@ export class UtilService {
pushNotification(idReferente)
{
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) => {
if (res.isEnabled || this.platform.is("ios")) {
......@@ -601,21 +612,13 @@ export class UtilService {
console.log('We do not have permission to send push notifications');
}
});
});*/
}
continuePush(idReferente)
{
/*this.push.createChannel({
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 = {
/*const options: PushOptions = {
android: {
//senderID:''
},
ios: {
alert: 'true',
......@@ -632,25 +635,46 @@ export class UtilService {
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) =>{
/*console.log(data.message);
console.log(data.title);
console.log(data.count);
console.log(data.sound);
console.log(data.image);
console.log(data.additionalData);*/
/*pushObject.on('notification').subscribe((data: any) =>{
if(data.additionalData.coldstart){
this.presentAlert(data.title+ " coldstart", "", data.message, ["OK"]);
this.initConfig(true, "notifiche");
}
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);
});
});*/
PushNotifications.addListener('registrationError',
(error: any) => {
console.log("Errore durante le notifiche: "+error);
}
);
}
savePushRegistrationId(id:string, idReferente)
......@@ -723,7 +747,6 @@ export class UtilService {
this.onResumeSubscription
console.log('resumed');
this.firstPause = true;
UtilService.isNotificaResume = false;
}
});
}
......@@ -793,7 +816,8 @@ export class UtilService {
}
async redirectToFirstPage(nextPage) {
var idReferente = await this.getIdUser();
var idReferente = null;
while(idReferente == null) idReferente = await this.getIdUser();
AuthService.isClienteLoggato = await this.getIsCliente();
if(AuthService.isClienteLoggato) this.apriPagina(nextPage);
else
......@@ -804,12 +828,13 @@ export class UtilService {
}
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{
if(!UtilService.isNotificaResume){
UtilService.isNotificaResume = true;
return;
}
if(res.autorizzato && this.startup && this.primaRestart)
{
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