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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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