fix ios notifications

This commit is contained in:
Lorito Tiago
2023-10-09 14:15:21 +01:00
parent 76f8ac976a
commit cca49822b3
70 changed files with 7451 additions and 44713 deletions
+44 -17
View File
@@ -15,6 +15,8 @@ import { Capacitor } from '@capacitor/core';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
import { FCM } from '@capacitor-community/fcm';
@Injectable({
providedIn: 'root'
@@ -51,6 +53,9 @@ export class NotificationsService {
private afMessaging: AngularFireMessaging,
public NotificationHolderService: NotificationHolderService) {
this.onReciveForeground();
this.onReciveBackground();
}
getTokenByUserIdAndId(user, userID) {
@@ -65,10 +70,11 @@ export class NotificationsService {
if (!this.isPushNotificationsAvailable) {
return false
}
PushNotifications.requestPermissions().then(result => {
PushNotifications.requestPermissions().then(async (result) => {
if (result.receive === 'granted') {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
this.getAndpostToken("")
} else {
// Show some error
}
@@ -77,19 +83,31 @@ export class NotificationsService {
}
}
getAndpostToken(username) {
private getAndpostToken(username) {
const geturl = environment.apiURL + 'notifications/token';
if (this.platform.is('mobile')) {
if (!this.isPushNotificationsAvailable) {
return false
}
if (this.platform.is('ios')) {
FCM.getToken()
.then(r => {
this.postToken(r.token, geturl)
this.token = r.token
// alert(this.token)
})
.catch(err => console.log(err));
} else {
PushNotifications.addListener('registration',
(token: Token) => {
this.postToken(token.value, geturl)
this.token = token.value
}
);
}
PushNotifications.addListener('registration',
(token: Token) => {
this.postToken(token.value, geturl)
this.token = token.value
}
);
} else {
this.afMessaging.requestToken.subscribe(
(token) => {
@@ -103,7 +121,6 @@ export class NotificationsService {
}
);
}
}
@@ -148,14 +165,18 @@ export class NotificationsService {
PushNotifications.addListener('registrationError',
(error: any) => {
this.active = false
this.active = false;
(() => {
throw ("error" + error.error)
})();
}
);
}
onReciveForeground() {
if(this.platform.is('mobile')) {
if (this.platform.is('mobile')) {
if (!this.isPushNotificationsAvailable) {
return false
@@ -174,9 +195,9 @@ export class NotificationsService {
this.afMessaging.messages.subscribe((notification) => {
this.storenotification(notification)
this.notificationReceived.emit();
this.eventtrigger.publishSomeData({
notification: "recive"
})
this.eventtrigger.publishSomeData({
notification: "recive"
})
// Handle the received message, e.g., show a notification
});
}
@@ -190,7 +211,7 @@ export class NotificationsService {
onReciveBackground() {
if(this.platform.is('mobile')) {
if (this.platform.is('mobile')) {
if (!this.isPushNotificationsAvailable) {
return false
}
@@ -285,7 +306,7 @@ export class NotificationsService {
notificatinsRoutes = (notification) => {
console.log('BACK BACK',notification)
console.log('BACK BACK', notification)
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
@@ -336,8 +357,14 @@ export class NotificationsService {
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
} else if (notification.notification.data.Service === "chat") {
let navigationExtras: NavigationExtras = { queryParams: { "roomId": notification.notification.data.IdObject, } };
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
this.zone.run(() => this.router.navigate(['/home/chat']));
setTimeout(() => {
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
}, 200);
}
}