Integración OneSignal y configuración HTTP nativo

- Configurar OneSignal con nuevo App ID
- Agregar network_security_config.xml para permitir HTTP
- Habilitar CapacitorHttp nativo en capacitor.config.ts
- Actualizar SDK a Android 34
- Configurar API_URL fija (192.168.10.207:8080)
- Agregar onesignal.service.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CarlosTorres
2026-01-21 05:09:51 +00:00
parent dfcb1168b9
commit 103f7f45a0
11 changed files with 330 additions and 22 deletions

View File

@@ -9,20 +9,22 @@ android {
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle" apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies { dependencies {
implementation project(':capacitor-community-facebook-login')
implementation project(':capacitor-community-http')
implementation project(':capacitor-app') implementation project(':capacitor-app')
implementation project(':capacitor-browser')
implementation project(':capacitor-camera')
implementation project(':capacitor-filesystem')
implementation project(':capacitor-geolocation')
implementation project(':capacitor-haptics') implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard') implementation project(':capacitor-keyboard')
implementation project(':capacitor-preferences')
implementation project(':capacitor-splash-screen')
implementation project(':capacitor-status-bar') implementation project(':capacitor-status-bar')
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0" implementation project(':codetrix-studio-capacitor-google-auth')
implementation "com.android.support:support-v4:27.+" implementation "com.onesignal:OneSignal:5.1.38"
implementation "com.facebook.android:facebook-android-sdk:5.13.0" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10"
implementation "com.google.android.gms:play-services-auth:15.0.1"
implementation "com.google.android.gms:play-services-identity:15.0.1"
implementation "com.google.android.gms:play-services-location:16.+"
implementation "com.onesignal:OneSignal:3.16.0"
} }
apply from: "../../node_modules/cordova-plugin-googlemaps/src/android/frameworks/tbxml-android.gradle"
apply from: "../../node_modules/cordova-plugin-googlemaps/src/android/frameworks/pgm-custom.gradle"
apply from: "../../node_modules/onesignal-cordova-plugin/build-extras-onesignal.gradle" apply from: "../../node_modules/onesignal-cordova-plugin/build-extras-onesignal.gradle"
if (hasProperty('postBuildExtras')) { if (hasProperty('postBuildExtras')) {

View File

@@ -7,6 +7,8 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.10.207</domain>
</domain-config>
</network-security-config>

View File

@@ -2,14 +2,41 @@
include ':capacitor-android' include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor') project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
include ':capacitor-community-facebook-login'
project(':capacitor-community-facebook-login').projectDir = new File('../node_modules/@capacitor-community/facebook-login/android')
include ':capacitor-community-http'
project(':capacitor-community-http').projectDir = new File('../node_modules/@capacitor-community/http/android')
include ':capacitor-app' include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android') project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android')
include ':capacitor-browser'
project(':capacitor-browser').projectDir = new File('../node_modules/@capacitor/browser/android')
include ':capacitor-camera'
project(':capacitor-camera').projectDir = new File('../node_modules/@capacitor/camera/android')
include ':capacitor-filesystem'
project(':capacitor-filesystem').projectDir = new File('../node_modules/@capacitor/filesystem/android')
include ':capacitor-geolocation'
project(':capacitor-geolocation').projectDir = new File('../node_modules/@capacitor/geolocation/android')
include ':capacitor-haptics' include ':capacitor-haptics'
project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/haptics/android') project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/haptics/android')
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-preferences'
project(':capacitor-preferences').projectDir = new File('../node_modules/@capacitor/preferences/android')
include ':capacitor-splash-screen'
project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/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')
include ':codetrix-studio-capacitor-google-auth'
project(':codetrix-studio-capacitor-google-auth').projectDir = new File('../node_modules/@codetrix-studio/capacitor-google-auth/android')

View File

@@ -1,7 +1,7 @@
ext { ext {
minSdkVersion = 22 minSdkVersion = 22
compileSdkVersion = 33 compileSdkVersion = 34
targetSdkVersion = 33 targetSdkVersion = 34
androidxActivityVersion = '1.7.0' androidxActivityVersion = '1.7.0'
androidxAppCompatVersion = '1.6.1' androidxAppCompatVersion = '1.6.1'
androidxCoordinatorLayoutVersion = '1.2.0' androidxCoordinatorLayoutVersion = '1.2.0'

View File

@@ -7,6 +7,11 @@ const config: CapacitorConfig = {
server: { server: {
androidScheme: 'https' androidScheme: 'https'
}, },
plugins: {
CapacitorHttp: {
enabled: true
}
},
cordova: { cordova: {
preferences: { preferences: {
ScrollEnabled: 'false', ScrollEnabled: 'false',

119
package-lock.json generated
View File

@@ -17,6 +17,7 @@
"@angular/platform-browser-dynamic": "~18.2.14", "@angular/platform-browser-dynamic": "~18.2.14",
"@angular/router": "~18.2.14", "@angular/router": "~18.2.14",
"@capacitor-community/facebook-login": "^7.0.1", "@capacitor-community/facebook-login": "^7.0.1",
"@capacitor-community/http": "^1.4.1",
"@capacitor/android": "^6.0.0", "@capacitor/android": "^6.0.0",
"@capacitor/app": "^6.0.0", "@capacitor/app": "^6.0.0",
"@capacitor/browser": "^6.0.0", "@capacitor/browser": "^6.0.0",
@@ -33,6 +34,7 @@
"@ionic/angular": "^8.7.17", "@ionic/angular": "^8.7.17",
"@ngx-translate/core": "~14.0.0", "@ngx-translate/core": "~14.0.0",
"@ngx-translate/http-loader": "~7.0.0", "@ngx-translate/http-loader": "~7.0.0",
"onesignal-cordova-plugin": "^5.2.19",
"rxjs": "~7.8.1", "rxjs": "~7.8.1",
"swiper": "^11.2.10", "swiper": "^11.2.10",
"tslib": "^2.6.0", "tslib": "^2.6.0",
@@ -3110,6 +3112,45 @@
"tslib": "^2.1.0" "tslib": "^2.1.0"
} }
}, },
"node_modules/@capacitor-community/http": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/@capacitor-community/http/-/http-1.4.1.tgz",
"integrity": "sha512-+pCkBXrwfm97UfjOgjV950H/qZ8SE36Mrcb46BlL1ps3VIsGuIO+AulL8GqTC6LewheRVtGJpRspNtneXQotNA==",
"license": "MIT",
"dependencies": {
"@capacitor/android": "^3.0.0",
"@capacitor/core": "^3.0.0",
"@capacitor/filesystem": "^1.0.0",
"@capacitor/ios": "^3.0.0"
}
},
"node_modules/@capacitor-community/http/node_modules/@capacitor/android": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/@capacitor/android/-/android-3.9.0.tgz",
"integrity": "sha512-YTPyrh1NozEuYXWGtfqN27TLXUrLbZX9fggyd4JQ1yMaUZTmLPm5dCuznONhQ49aPkJnUJB02JfpHy/qGwa2Lw==",
"license": "MIT",
"peerDependencies": {
"@capacitor/core": "^3.9.0"
}
},
"node_modules/@capacitor-community/http/node_modules/@capacitor/core": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/@capacitor/core/-/core-3.9.0.tgz",
"integrity": "sha512-j1lL0+/7stY8YhIq1Lm6xixvUqIn89vtyH5ZpJNNmcZ0kwz6K9eLkcG6fvq1UWMDgSVZg9JrRGSFhb4LLoYOsw==",
"license": "MIT",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/@capacitor-community/http/node_modules/@capacitor/filesystem": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@capacitor/filesystem/-/filesystem-1.1.0.tgz",
"integrity": "sha512-8O3UuvL8HNUEJvZnmn8yUmvgB1evtXfcF0oxIo3YbSlylqywJwS3JTiuhKmsvSxCdpbTy8IaTsutVh3gZgWbKg==",
"license": "MIT",
"peerDependencies": {
"@capacitor/core": "^3.0.0"
}
},
"node_modules/@capacitor/android": { "node_modules/@capacitor/android": {
"version": "6.2.1", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/@capacitor/android/-/android-6.2.1.tgz", "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-6.2.1.tgz",
@@ -3214,6 +3255,15 @@
"@capacitor/core": "^6.0.0" "@capacitor/core": "^6.0.0"
} }
}, },
"node_modules/@capacitor/ios": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-3.9.0.tgz",
"integrity": "sha512-GezPCJIujRHnF4wbrKJx6Q/mgFz0f9rmh/steTTXQZI+nEl6mHk6NWh8235p7YbhonYi5WD0rFNirrjGg1EaGw==",
"license": "MIT",
"peerDependencies": {
"@capacitor/core": "^3.9.0"
}
},
"node_modules/@capacitor/keyboard": { "node_modules/@capacitor/keyboard": {
"version": "6.0.4", "version": "6.0.4",
"resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-6.0.4.tgz", "resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-6.0.4.tgz",
@@ -12587,6 +12637,34 @@
"wrappy": "1" "wrappy": "1"
} }
}, },
"node_modules/onesignal-cordova-plugin": {
"version": "5.2.19",
"resolved": "https://registry.npmjs.org/onesignal-cordova-plugin/-/onesignal-cordova-plugin-5.2.19.tgz",
"integrity": "sha512-RGaEJTD3bFwxhsOZNgCB9XR31fLg8fy/PXclXMZfc8ohoKUq6jhEz0aE4AWON9XZx7eO+wbmd3dxn2U5AlZMKg==",
"engines": [
{
"name": "cordova-android",
"version": ">=4.0.0"
},
{
"name": "apple-xcode",
"version": ">=8.0.0"
},
{
"name": "apple-ios",
"version": ">=7.0.0"
},
{
"name": "cordova",
"version": ">=6.4.0"
},
{
"name": "cordova-ios",
"version": ">=4.3.0"
}
],
"license": "MIT"
},
"node_modules/onetime": { "node_modules/onetime": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",
@@ -18633,6 +18711,37 @@
} }
} }
}, },
"@capacitor-community/http": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/@capacitor-community/http/-/http-1.4.1.tgz",
"integrity": "sha512-+pCkBXrwfm97UfjOgjV950H/qZ8SE36Mrcb46BlL1ps3VIsGuIO+AulL8GqTC6LewheRVtGJpRspNtneXQotNA==",
"requires": {
"@capacitor/android": "^3.0.0",
"@capacitor/core": "^3.0.0",
"@capacitor/filesystem": "^1.0.0",
"@capacitor/ios": "^3.0.0"
},
"dependencies": {
"@capacitor/android": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/@capacitor/android/-/android-3.9.0.tgz",
"integrity": "sha512-YTPyrh1NozEuYXWGtfqN27TLXUrLbZX9fggyd4JQ1yMaUZTmLPm5dCuznONhQ49aPkJnUJB02JfpHy/qGwa2Lw=="
},
"@capacitor/core": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/@capacitor/core/-/core-3.9.0.tgz",
"integrity": "sha512-j1lL0+/7stY8YhIq1Lm6xixvUqIn89vtyH5ZpJNNmcZ0kwz6K9eLkcG6fvq1UWMDgSVZg9JrRGSFhb4LLoYOsw==",
"requires": {
"tslib": "^2.1.0"
}
},
"@capacitor/filesystem": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@capacitor/filesystem/-/filesystem-1.1.0.tgz",
"integrity": "sha512-8O3UuvL8HNUEJvZnmn8yUmvgB1evtXfcF0oxIo3YbSlylqywJwS3JTiuhKmsvSxCdpbTy8IaTsutVh3gZgWbKg=="
}
}
},
"@capacitor/android": { "@capacitor/android": {
"version": "6.2.1", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/@capacitor/android/-/android-6.2.1.tgz", "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-6.2.1.tgz",
@@ -18701,6 +18810,11 @@
"resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-6.0.3.tgz", "resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-6.0.3.tgz",
"integrity": "sha512-6yKF0+lRUZEEx1GDFWgnKHia974np7o1OgmRl/btL9cSMZh0TSDZTyDMH/qcy4AM39CfuIeLs4N4h5lwixXLuQ==" "integrity": "sha512-6yKF0+lRUZEEx1GDFWgnKHia974np7o1OgmRl/btL9cSMZh0TSDZTyDMH/qcy4AM39CfuIeLs4N4h5lwixXLuQ=="
}, },
"@capacitor/ios": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-3.9.0.tgz",
"integrity": "sha512-GezPCJIujRHnF4wbrKJx6Q/mgFz0f9rmh/steTTXQZI+nEl6mHk6NWh8235p7YbhonYi5WD0rFNirrjGg1EaGw=="
},
"@capacitor/keyboard": { "@capacitor/keyboard": {
"version": "6.0.4", "version": "6.0.4",
"resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-6.0.4.tgz", "resolved": "https://registry.npmjs.org/@capacitor/keyboard/-/keyboard-6.0.4.tgz",
@@ -25067,6 +25181,11 @@
"wrappy": "1" "wrappy": "1"
} }
}, },
"onesignal-cordova-plugin": {
"version": "5.2.19",
"resolved": "https://registry.npmjs.org/onesignal-cordova-plugin/-/onesignal-cordova-plugin-5.2.19.tgz",
"integrity": "sha512-RGaEJTD3bFwxhsOZNgCB9XR31fLg8fy/PXclXMZfc8ohoKUq6jhEz0aE4AWON9XZx7eO+wbmd3dxn2U5AlZMKg=="
},
"onetime": { "onetime": {
"version": "5.1.2", "version": "5.1.2",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz",

View File

@@ -21,6 +21,7 @@
"@angular/platform-browser-dynamic": "~18.2.14", "@angular/platform-browser-dynamic": "~18.2.14",
"@angular/router": "~18.2.14", "@angular/router": "~18.2.14",
"@capacitor-community/facebook-login": "^7.0.1", "@capacitor-community/facebook-login": "^7.0.1",
"@capacitor-community/http": "^1.4.1",
"@capacitor/android": "^6.0.0", "@capacitor/android": "^6.0.0",
"@capacitor/app": "^6.0.0", "@capacitor/app": "^6.0.0",
"@capacitor/browser": "^6.0.0", "@capacitor/browser": "^6.0.0",
@@ -37,6 +38,7 @@
"@ionic/angular": "^8.7.17", "@ionic/angular": "^8.7.17",
"@ngx-translate/core": "~14.0.0", "@ngx-translate/core": "~14.0.0",
"@ngx-translate/http-loader": "~7.0.0", "@ngx-translate/http-loader": "~7.0.0",
"onesignal-cordova-plugin": "^5.2.19",
"rxjs": "~7.8.1", "rxjs": "~7.8.1",
"swiper": "^11.2.10", "swiper": "^11.2.10",
"tslib": "^2.6.0", "tslib": "^2.6.0",

View File

@@ -9,6 +9,7 @@ import { LanguageService } from './services/language.service';
import { AlertService } from './services/alert.service'; import { AlertService } from './services/alert.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { Capacitor } from '@capacitor/core'; import { Capacitor } from '@capacitor/core';
import { OneSignalService } from './services/onesignal.service';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@@ -29,9 +30,12 @@ export class AppComponent {
private events: EventService, private events: EventService,
private alertService: AlertService, private alertService: AlertService,
private loadingCtrl: LoadingController, private loadingCtrl: LoadingController,
private oneSignalService: OneSignalService,
) { ) {
this.initializeApp(); this.initializeApp();
this.events.subscribe('set_role', role => { this.events.subscribe('set_role', role => {
// Set OneSignal user tags when role is set (user logged in)
this.setupOneSignalUser(role);
if (role >= 2){ if (role >= 2){
this.appPages = [ this.appPages = [
{ {
@@ -104,23 +108,32 @@ export class AppComponent {
await StatusBar.setStyle({ style: Style.Light }); await StatusBar.setStyle({ style: Style.Light });
await StatusBar.setOverlaysWebView({ overlay: false }); await StatusBar.setOverlaysWebView({ overlay: false });
await StatusBar.setBackgroundColor({ color: '#0080ff' }); await StatusBar.setBackgroundColor({ color: '#0080ff' });
// TODO: Implement OneSignal with Capacitor plugin
// this.handlerNotifications(); // Initialize OneSignal push notifications
await this.oneSignalService.init();
} }
this.languageService.getDefaultLanguage(); this.languageService.getDefaultLanguage();
this.authService.getToken(); this.authService.getToken();
} }
private async setupOneSignalUser(role: number) {
if (this.authService.token && this.authService.token.user_id) {
await this.oneSignalService.setUserId(this.authService.token.user_id);
await this.oneSignalService.setUserRole(role);
}
}
// When Logout Button is pressed // When Logout Button is pressed
async logout() { async logout() {
this.loading = await this.loadingCtrl.create(); this.loading = await this.loadingCtrl.create();
await this.loading.present(); await this.loading.present();
this.authService.logout().subscribe( this.authService.logout().subscribe(
data => { async data => {
this.alertService.presentToast(this.translateService.instant('alerts.logout')); this.alertService.presentToast(this.translateService.instant('alerts.logout'));
// TODO: Implement OneSignal tag clearing with Capacitor // Clear OneSignal user tags on logout
await this.oneSignalService.logout();
}, },
error => { error => {
this.loading.dismiss(); this.loading.dismiss();
@@ -136,7 +149,4 @@ export class AppComponent {
async openUrl(url: string) { async openUrl(url: string) {
await Browser.open({ url }); await Browser.open({ url });
} }
// TODO: Re-implement push notifications with OneSignal Capacitor plugin
// private handlerNotifications() { ... }
} }

View File

@@ -4,13 +4,11 @@ import { Injectable } from '@angular/core';
providedIn: 'root' providedIn: 'root'
}) })
export class EnvService { export class EnvService {
// Usa el mismo host pero puerto 8080 para el API API_URL = 'http://192.168.10.207:8080/api/';
API_URL = (typeof window !== 'undefined' && window.location.hostname !== 'localhost')
? `http://${window.location.hostname}:8080/api/`
: 'http://localhost:8080/api/';
SECRET = 'wBIIKuDbrxNKzQhAUGiZLoaoQ4MichAN3wP2AP7B'; SECRET = 'wBIIKuDbrxNKzQhAUGiZLoaoQ4MichAN3wP2AP7B';
MERCHANT_ID = 'm9k4beuso5az0wjqztvt'; MERCHANT_ID = 'm9k4beuso5az0wjqztvt';
PUBLIC_API_KEY = 'pk_9465179493384689a8d2da9adc825411'; PUBLIC_API_KEY = 'pk_9465179493384689a8d2da9adc825411';
ONESIGNAL_APP_ID = 'c854ae89-7ff7-4216-a70e-5fdff0cd8e10';
constructor() { } constructor() { }
} }

View File

@@ -0,0 +1,132 @@
import { Injectable } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { EnvService } from './env.service';
import { Router } from '@angular/router';
declare var OneSignalPlugin: any;
@Injectable({
providedIn: 'root'
})
export class OneSignalService {
private initialized = false;
constructor(
private env: EnvService,
private router: Router
) { }
async init(): Promise<void> {
if (this.initialized || !Capacitor.isNativePlatform()) {
return;
}
try {
// Initialize OneSignal
OneSignalPlugin.initialize(this.env.ONESIGNAL_APP_ID);
// Request notification permission
OneSignalPlugin.Notifications.requestPermission(true).then((accepted: boolean) => {
console.log('OneSignal notification permission:', accepted ? 'accepted' : 'denied');
});
// Handle notification clicks
OneSignalPlugin.Notifications.addEventListener('click', (event: any) => {
console.log('OneSignal notification clicked:', event);
this.handleNotificationClick(event);
});
// Handle foreground notifications
OneSignalPlugin.Notifications.addEventListener('foregroundWillDisplay', (event: any) => {
console.log('OneSignal notification received in foreground:', event);
// Display the notification
event.getNotification().display();
});
this.initialized = true;
console.log('OneSignal initialized successfully');
} catch (error) {
console.error('Error initializing OneSignal:', error);
}
}
async setUserId(userId: number | string): Promise<void> {
if (!Capacitor.isNativePlatform()) {
return;
}
try {
// Set user tag for targeting
OneSignalPlugin.User.addTag('iChamba_ID', String(userId));
console.log('OneSignal user tag set:', userId);
} catch (error) {
console.error('Error setting OneSignal user tag:', error);
}
}
async setUserRole(roleId: number | string): Promise<void> {
if (!Capacitor.isNativePlatform()) {
return;
}
try {
OneSignalPlugin.User.addTag('iChamba_Role', String(roleId));
console.log('OneSignal role tag set:', roleId);
} catch (error) {
console.error('Error setting OneSignal role tag:', error);
}
}
async clearTags(): Promise<void> {
if (!Capacitor.isNativePlatform()) {
return;
}
try {
OneSignalPlugin.User.removeTags(['iChamba_ID', 'iChamba_Role']);
console.log('OneSignal tags cleared');
} catch (error) {
console.error('Error clearing OneSignal tags:', error);
}
}
async logout(): Promise<void> {
await this.clearTags();
}
private handleNotificationClick(event: any): void {
const data = event?.notification?.additionalData;
if (data) {
// Handle navigation based on notification data
if (data.route) {
this.router.navigate([data.route]);
} else if (data.type) {
switch (data.type) {
case 'contract':
this.router.navigate(['/contracts']);
break;
case 'postulation':
this.router.navigate(['/postulations']);
break;
default:
this.router.navigate(['/dashboard']);
}
}
}
}
async getPlayerId(): Promise<string | null> {
if (!Capacitor.isNativePlatform()) {
return null;
}
try {
const deviceState = await OneSignalPlugin.User.pushSubscription.getId();
return deviceState || null;
} catch (error) {
console.error('Error getting OneSignal player ID:', error);
return null;
}
}
}