Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Commit 0c96de3

Browse files
author
yyosifov
committed
Improve documentation, Added details how to install from NPM
1 parent 2f7b4f8 commit 0c96de3

1 file changed

Lines changed: 43 additions & 29 deletions

File tree

README.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ The code for the Push Plugin for NativeScript.
173173

174174
or use an existing one.
175175

176-
- Add the Push Plugin. This will install the push plugin in node_module, in the root of the project. When adding a new platform (or using an existing one) the plugin will be added there as well.
176+
- Add the Push Plugin (from NPM). This will install the push plugin in node_module, in the root of the project. When adding a new platform (or using an existing one) the plugin will be added there as well.
177177

178-
tns plugin add C:\nativescript-push\push-plugin
178+
tns plugin add nativescript-push-notifications
179179

180180
### Android
181181

@@ -188,10 +188,10 @@ The code for the Push Plugin for NativeScript.
188188
tns library add android C:\Users\your_user_name\AppData\Local\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs
189189

190190

191-
- Add sample code in main-view-model.js like this one to subscribe and receive messages (Enter your google project id in the options of the register method):
191+
- Add sample code in app/main-view-model.js in the function HelloWorldModel() like this one to subscribe and receive messages (Enter your google project id in the options of the register method):
192192

193193
```javascript
194-
var pushPlugin = require("push-plugin");
194+
var pushPlugin = require("nativescript-push-notifications");
195195
var self = this;
196196
pushPlugin.register({ senderID: 'your-google-project-id' }, function (data){
197197
self.set("message", "" + JSON.stringify(data));
@@ -206,6 +206,8 @@ The code for the Push Plugin for NativeScript.
206206

207207
tns run android
208208

209+
- The access token is written in the console and in the message area, after subscribing (Look for ObtainTokenThread log record). When sending a notification, the message below the TAP button should be changed with the message received.
210+
209211
### iOS
210212

211213
- Edit the package.json file in the root of application, by changing the bundle identifier to match the one from your Push Certificate. For example:
@@ -215,36 +217,34 @@ The code for the Push Plugin for NativeScript.
215217

216218
tns platform add ios
217219

218-
- Add sample code in main-view-model.js like this one to subscribe and receive messages (Enter your google project id in the options of the register method):
220+
- Add sample code in app/main-view-model.js in the function HelloWorldModel() like this one to subscribe and receive messages (Enter your google project id in the options of the register method):
219221

220222
```javascript
221223
var pushPlugin = require("nativescript-push-notifications");
222224
var self = this;
223225
var iosSettings = {
224-
iOS: {
225-
badge: true,
226-
sound: true,
227-
alert: true,
228-
interactiveSettings: {
229-
actions: [{
230-
identifier: 'READ_IDENTIFIER',
231-
title: 'Read',
232-
activationMode: "foreground",
233-
destructive: false,
234-
authenticationRequired: true
235-
}, {
236-
identifier: 'CANCEL_IDENTIFIER',
237-
title: 'Cancel',
238-
activationMode: "foreground",
239-
destructive: true,
240-
authenticationRequired: true
241-
}],
242-
categories: [{
243-
identifier: 'READ_CATEGORY',
244-
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
245-
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
246-
}]
247-
}
226+
badge: true,
227+
sound: true,
228+
alert: true,
229+
interactiveSettings: {
230+
actions: [{
231+
identifier: 'READ_IDENTIFIER',
232+
title: 'Read',
233+
activationMode: "foreground",
234+
destructive: false,
235+
authenticationRequired: true
236+
}, {
237+
identifier: 'CANCEL_IDENTIFIER',
238+
title: 'Cancel',
239+
activationMode: "foreground",
240+
destructive: true,
241+
authenticationRequired: true
242+
}],
243+
categories: [{
244+
identifier: 'READ_CATEGORY',
245+
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
246+
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
247+
}]
248248
},
249249
notificationCallbackIOS: function (data) {
250250
self.set("message", "" + JSON.stringify(data));
@@ -253,9 +253,23 @@ The code for the Push Plugin for NativeScript.
253253

254254
pushPlugin.register(iosSettings, function (data) {
255255
self.set("message", "" + JSON.stringify(data));
256+
257+
// Register the interactive settings
258+
if(settings.interactiveSettings) {
259+
pushPlugin.registerUserNotificationSettings(function() {
260+
alert('Successfully registered for interactive push.');
261+
}, function(err) {
262+
alert('Error registering for interactive push: ' + JSON.stringify(err));
263+
});
256264
}, function() { });
257265
```
258266
267+
- Run the code
268+
269+
tns run ios
270+
271+
- Send notifications
272+
259273
## Troubleshooting
260274
261275
In case the application doesn't work as expected. Here are some things you can verify

0 commit comments

Comments
 (0)