Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

vipera-npm-registry / de-push-proxy-plugin   js

Repository URL to install this package:

Version: 1.0.1 

/ README.md

Dynamic Engine Push Proxy Plugin

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.

Installation

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>

DEPushNotificationHandler

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;
    }
}

DEPushNotificationHandlerRegistry

To register a new instance of the DEPushNotificationHandler implementation you need to register it via DEPushNotificationHandlerRegistry singleton:

customHandlerInstance = new CustomFCMHandler():

....

DEPushNotificationHandlerRegistry.getInstance().registerNotificationHandler(customHandlerInstance);

iOS Usage

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"