Skip to content

Commit c03ef5f

Browse files
committed
added installationId and updated readme
1 parent 51c1d4a commit c03ef5f

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ Registers the given native push token for push notifications with Azure.
6666
* **registerWithTemplate(string, string, string): Promise**
6767
Registers the given native push token, template name and template for push notifications with Azure. For more information about templates see the usage [below](#register-with-a-template).
6868

69+
* **registerWithTags(string, string[]): Promise**
70+
Registers the given native push token for push notifications with Azure and associates the given tags with the device installation. You can read more about tags [here](https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-tags-segment-push-message).
71+
72+
* **registerWithTagsAndTemplate(string, string[], string, string): Promise**
73+
This combines the above 2 methods, so you can register both with a template and tags.
74+
6975
* **unregister(): Promise**
7076
Unregisters the device from Azure push notifications.
7177

78+
#### Properties
79+
* **installationId** - *string*
80+
Returns the `installationId` of the device what is registered with Azure's Notification Hubs. This is usefull, for example, in case you need custom tags and you need to call your backend to add the tags.
81+
7282
### `MobileServiceUser`
7383

7484
#### Static Methods

demo/app/main-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export function onPushRegisterTap() {
167167
pushPlugin.onMessageReceived(pushSettings.notificationCallbackAndroid);
168168
}
169169
client.push.register(data)
170-
.then(() => console.log("Azure Register OK!"))
170+
.then(() => console.log("Azure Register OK!", client.push.installationId))
171171
.catch((e) => console.log(e));
172172
}, (e) => { console.log(e); });
173173
}

demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"readme": "Azure Mobile Apps Service application",
55
"nativescript": {
66
"id": "inc.tangra.azuremobileservicessample",
7-
"tns-android": {
7+
"tns-ios": {
88
"version": "3.2.0"
99
},
10-
"tns-ios": {
10+
"tns-android": {
1111
"version": "3.2.0"
1212
}
1313
},

push/push-common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import * as definition from "nativescript-azure-mobile-apps/push";
1717

1818
export abstract class MobileServicePush implements definition.MobileServicePush {
1919
protected _msPush;
20+
21+
abstract get installationId(): string;
2022

2123
constructor(nativeValue: any) {
2224
this._msPush = nativeValue;

push/push.android.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const PUSH_PLATFORM = "gcm";
2525
export class MobileServicePush extends common.MobileServicePush {
2626
protected _msPush: com.microsoft.windowsazure.mobileservices.notifications.MobileServicePush;
2727

28+
get installationId(): string {
29+
return com.microsoft.windowsazure.mobileservices.MobileServiceApplication.getInstallationId(application.android.currentContext);
30+
}
31+
2832
public register(registrationId: string): Promise<any> {
2933
return new Promise((resolve, reject) => {
3034
try {
@@ -58,7 +62,6 @@ export class MobileServicePush extends common.MobileServicePush {
5862
public registerWithTagsAndTemplate(registrationId: string, tags: string[], templateName: string, templateBody: string): Promise<any> {
5963
return new Promise((resolve, reject) => {
6064
try {
61-
const installationId = com.microsoft.windowsazure.mobileservices.MobileServiceApplication.getInstallationId(application.android.currentContext);
6265
let tagsAsList: java.util.List<string> = null;
6366
let templates: java.util.HashMap<string, com.microsoft.windowsazure.mobileservices.notifications.InstallationTemplate> = null;
6467

@@ -72,7 +75,7 @@ export class MobileServicePush extends common.MobileServicePush {
7275
}
7376

7477
const installation = new com.microsoft.windowsazure.mobileservices.notifications.Installation(
75-
installationId,
78+
this.installationId,
7679
PUSH_PLATFORM,
7780
registrationId,
7881
null,

push/push.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ declare module "nativescript-azure-mobile-apps/push" {
1919

2020
constructor(nativeValue: any);
2121

22+
public readonly installationId: string;
23+
2224
public register(registrationId: string): Promise<any>;
2325
public registerWithTemplate(registrationId: string, templateName: string, templateBody: string): Promise<any>;
2426
public registerWithTags(registrationId: string, tags: string[]): Promise<any>;

push/push.ios.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const PUSH_PLATFORM = "apns";
2323
export class MobileServicePush extends common.MobileServicePush {
2424
protected _msPush: MSPush;
2525

26+
get installationId(): string {
27+
return this._msPush.installationId;
28+
}
29+
2630
public register(registrationId: string): Promise<any> {
2731
return new Promise((resolve, reject) => {
2832
try {

0 commit comments

Comments
 (0)