Rich and interactive push notifications for iOS, Android and Web. Enhance your apps with location based messages that really work.
To install the plugin to your Cordova project use the Cordova CLI Tool:
$ cordova plugin add cordova-plugin-notificare-push
Android
- Minimal required Android SDK version is 10 (Gingerbread / 2.3.x), but latest versions of Cordova require 14 (Ice Cream Sandwich / 4.0.x)
- Setup GCM in Notificare (and optionally Google Maps) as described in Create Application and Platform Configuration
iOS
- iOS 6+.
- Manage certificates and API keys as explained in Create Application and Platform Configuration
Previous versions of the SDK required Eclipse to link to dependencies. Since plugin version 1.5.2 this is all done through Gradle.
Since the Cordova plugin installer doesn't add all necessary changes to the AndroidManifest.xml, you might have to add some settings manually in that file. In any case, your application needs to be of class re.notifica.cordova.BaseApplication
<application
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:name="re.notifica.cordova.BaseApplication">
Edit the Notificare.plist and enter your keys from the Notificare Dashboard
Edit assets/notificareconfig.properties and enter your keys from the Notificare Dashboard plus the SenderId from your Google API Console
Be aware that when you upgrade platforms or the plugin, you may need to change the contents of these files again. Always check after updating.
An instance of the plugin is accessible in JavaScript as Notificare
.
To enable push notifications in your Cordova app, you only need to do 2 things in your deviceReady
listener:
- listen for a
ready
event to be emitted from Notificare, then callNotificare.enableNotifications()
. - listen for a
registration
event to be emitted from Notificare. This will give you a deviceId to be registered to the Notificare API with optional userId and userName that are specific for your user.
onDeviceReady: function() {
Notificare.on('ready', function(applicationInfo) {
console.log(JSON.stringify(applicationInfo));
Notificare.enableNotifications();
});
Notificare.on('registration', function(deviceId) {
// Register the device on Notificare API
Notificare.registerDevice(deviceId, '[email protected]', 'Test User', function() {
console.log('registered with Notificare');
}, function(error) {
console.log(error);
});
});
Notificare.start();
});
By enabling location updates, the Notificare plugin will automatically take care of updating the device's location and fetching nearby geofences.
Be careful to only enable location updates after the device is registered, this will make sure all updates are registered correctly.
onDeviceReady: function() {
Notificare.on('ready', function(applicationInfo) {
console.log(JSON.stringify(applicationInfo));
Notificare.enableNotifications();
});
Notificare.on('registration', function(deviceId) {
// Register the device on Notificare API
Notificare.registerDevice(deviceId, '[email protected]', 'Test User', function() {
console.log('registered with Notificare');
Notificare.enableLocationUpdates();
}, function(error) {
console.log(error);
});
});
});
You can add, remove and clean tags for the device from within your Javascript code. Again, make sure you registered the device first before you call any of these methods.
Notificare.addDeviceTags(['tag1','tag2'], function() {
console.log('added tags');
}, function(error) {
console.log(error);
});
Notificare.removeDeviceTag('tag2', function() {
console.log('removed tag');
}, function(error) {
console.log(error);
});
Notificare.clearDeviceTags(function() {
console.log('cleared all tags');
}, function(error) {
console.log(error);
});
Notificare.fetchDeviceTags(function(tags) {
console.log('tags registered for this device: ' + tags);
}, function(error) {
console.log(error);
});
Both locationUpdates and notifications can be disabled by calling disableLocationUpdates()
and disableLocationUpdates()
In Android, simply add an intent filter to your (Cordova) Activity in the AndroidManifest.
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="MyCordovaActivity" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!--
This activity will receive notification opened intents
-->
<intent-filter>
<action android:name="re.notifica.intent.action.NotificationOpened" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In iOS, you only need to tell the plugin to handle notifications by calling Notificare.setHandleNotification(true) in JS. See below.
In your device ready logic, tell the plugin to handle incoming notifications, then add an event listener for incoming notifications
onDeviceReady: function() {
Notificare.setHandleNotification(true);
Notificare.on('ready', function(applicationInfo) {
Notificare.enableNotifications();
});
Notificare.on('registration', function(deviceId) {
// ...
});
Notificare.on('notification', function(notification) {
if (notification.extra.myTypeFlag == 'special') {
// Here you could show notification in your view, or ignore it
// In iOS, don't use any blocking calls like window.alert()
// If you do want to log the notification as opened, you should call
// Notificare.logOpenNotification(notification);
} else {
// open like normal
Notificare.openNotification(notification);
}
});
Notificare.start();
});
If the app crashes or misbehaves, please check logcat for errors
Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
This means that you didn't make your application to be a re.notifica.cordova.BaseApplication. Please change the android:name attribute of your element in your manifest
NotificareLogger: re.notifica.NotificareError: Authentication error, please check your keys
This means you didn't add the application keys and secrets to your notificareconfig.properties
If you see a modal dialog popping up at launch saying you have a mising or invalid plist, make sure you fill in application keys and secrets in Notificare.plist
For more info on customizing the default behavior and looks of the Notificare UI, take a look at the platforms' respective docs: