Repository URL to install this package:
This plugin adds the push notifications dispatch mechanism to the listeners who demand it: when a push is received from the operating system it has a single entry point. if you need to handle push from multiple points in your app you can use this listener-based dispatcher.
NOTE:This plugin depends on phonegap-plugin-push plugin.
cordova plugin add de-push-proxy-plugin --save
After the installation your AndroidManifest.xml should contain these lines (only for Android platform):
<service android:exported="false" android:name="com.vipera.pushproxy.DEFCMIntentService">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
To create a listener you must implement the DEPushNotificationHandler interface:
public interface DEPushNotificationHandler {
public boolean canHandleMessage(String from, Bundle extras);
}
The canHandleMessage method must return a boolean value depending on whether the listener has managed push reception. If the push is handled it will have to return TRUE.
Example:
public class CustomFCMHandler implements DEPushNotificationHandler {
@Override
public boolean canHandleMessage(String from, Bundle extras) {
Log.d("canHandleMessage called for "+ from +" extras " + extras, "");
return true;
}
}
To register a new instance of the DEPushNotificationHandler implementation you need to register it via DEPushNotificationHandlerRegistry singleton:
customHandlerInstance = new CustomFCMHandler():
....
DEPushNotificationHandlerRegistry.getInstance().registerNotificationHandler(customHandlerInstance);
To use this plugin in iOS you need to perform some changes manually. Basically you have to add these lines at the start in the AppDelegate methods (probably in 'AppDelegate+notification.m' source file) like these:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"didReceiveNotification with fetchCompletionHandler");
if ([[DEPushNotificationHandlerRegistry sharedInstance] canHandleMessage:application didReceiveRemoteNotification:userInfo]){
return;
}
....
and
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"clicked on the shade");
if ([[DEPushNotificationHandlerRegistry sharedInstance] canHandleMessage:application didReceiveRemoteNotification:userInfo]){
return;
}
...
and import
#import "DEPushNotificationHandlerRegistry.h"