Closed objecteer closed 1 year ago
@objecteer checking it.
@objecteer I could not reproduce it so far with a blank ionic capacitor project, so could you please elaborate on the issue? Does that happen on Android, iOS, or both? Do the callbacks not fire when your app is in foreground, background or closed states (or in all these cases)? What Pushwoosh plugin version do you use in your project?
The problem was on android platform. I used pushwoosh plugin version 8.3.9. I tested the application again and found that the application was always failed to register device. The error return from the function was null.
I have tested with version 8.3.10 and still had a problem with registerDevice function. I also test on ios platform and had the same problem.
I have fixed the problem on both android and ios as follows:
I'm developing an application using Ionic Capacitor as follows: Ionic:
Ionic CLI : 6.20.4 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 6.3.9 @angular-devkit/build-angular : 15.0.2 @angular-devkit/schematics : 15.0.2 @angular/cli : 15.0.2 @ionic/angular-toolkit : 6.1.0
Capacitor:
Capacitor CLI : 4.6.1 @capacitor/android : 4.6.1 @capacitor/core : 4.6.1 @capacitor/ios : 4.6.1
Utility:
cordova-res : 0.15.4 native-run : 1.7.1
System:
NodeJS : v14.20.0 (/usr/local/bin/node) npm : 6.14.17 OS : macOS
I've added the following tags to AndroidManifest.xml
<meta-data android:name="com.pushwoosh.log_level" android:value="DEBUG" />
<meta-data android:name="com.pushwoosh.foreground_push" android:value="false" />
<meta-data android:name="com.pushwoosh.notification_service_extension" android:value="com.pushwoosh.plugin.pushnotifications.PushwooshNotificationServiceExtension" />
<meta-data android:name="com.pushwoosh.internal.plugin_provider" android:value="com.pushwoosh.plugin.internal.PhonegapPluginProvider" />
<service android:exported="false" android:name="com.pushwoosh.plugin.pushnotifications.CustomFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
and added the following tags to res/xml/config.xml
<access origin="*.pushwoosh.com" />
<feature name="PushNotification">
<param name="android-package" value="com.pushwoosh.plugin.pushnotifications.PushNotifications" onload="true"/>
</feature>
<resource-file src="google-services.json" target="app/google-services.json" />
I've tried the following code with ionic cordova with cordova-android 11.0.0 and it works correctly.
document.addEventListener('push-notification', (event: any) => {
let notification = event ? event.notification : undefined;
this.type = notification && notification.data ? notification.data.type : undefined;
});
document.addEventListener('push-receive', (event: any) => {
let notification = event ? event.notification : undefined;
if (notification && notification.foreground) {
this.notificationSubject.next(notification);
}
});
this.pushwoosh = cordova.require('pushwoosh-cordova-plugin.PushNotification');
this.pushwoosh.onDeviceReady({
appid: PushwooshApplicationCode,
projectid: GoogleProjectId
});