Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Very simple way to implement iOS push notifications in NativeScript using an exports function instead of a large, separate, observable class setup which is all I could find any where online.
var page;
var observable = require("data/observable");
var pageData = new observable.Observable();
exports.loaded = function(args) {
page = args.object;
var pushPlugin = require("nativescript-push-notifications");
var self = pageData;
var iosSettings = {
badge: true,
sound: true,
alert: true,
interactiveSettings: {
actions: [{
identifier: 'READ_IDENTIFIER',
title: 'Read',
activationMode: "foreground",
destructive: false,
authenticationRequired: true
}, {
identifier: 'CANCEL_IDENTIFIER',
title: 'Cancel',
activationMode: "foreground",
destructive: true,
authenticationRequired: true
}],
categories: [{
identifier: 'READ_CATEGORY',
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
}]
},
notificationCallbackIOS: function (data) {
self.set("message", "" + JSON.stringify(data));
}
};
pushPlugin.register(iosSettings, function (data) {
self.set("message", "" + JSON.stringify(data));
// Register the interactive settings
if(iosSettings.interactiveSettings) {
pushPlugin.registerUserNotificationSettings(function(success) {
console.dump(success);
alert('Successfully registered for interactive push.');
}, function(err) {
alert('Error registering for interactive push: ' + JSON.stringify(err));
});
}
}, function() { });
page.bindingContext = pageData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment