Skip to content

Instantly share code, notes, and snippets.

@mqtik
Forked from davorpeic/notifications.ts
Created September 13, 2018 14:08
Show Gist options
  • Save mqtik/ce659e96a8e137f47acf293c645798f7 to your computer and use it in GitHub Desktop.
Save mqtik/ce659e96a8e137f47acf293c645798f7 to your computer and use it in GitHub Desktop.
OneSignal service
import { Injectable } from "@angular/core";
import * as application from 'application';
let TnsOneSignal = require('nativescript-onesignal').TnsOneSignal;
@Injectable()
export class NotificationService {
constructor() {}
getUserIds():Promise<any> {
let p = new Promise((resolve, reject) => {
TnsOneSignal.IdsAvailable(function(userId,registrationId) {
if(userId != 'nil' || userId != "" || userId != undefined) {
console.log("trying to get IDS...", userId);
resolve(userId);
}
else {
reject('No IDs available');
}
});
});
return p;
};
// {mytag1: "value1", mytag2: "value2", mytag3: "value3"}
saveTags(tags){
if(application.ios) {
TnsOneSignal.sendTags(tags);
}
if(application.android) {
com.onesignal.OneSignal.sendTags(JSON.stringify(tags));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment