Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 229594

App is run forever

$
0
0

Here is my code

import { Component } from '@angular/core';
import { NavController,Platform } from 'ionic-angular';
import { OneSignal } from '@ionic-native/onesignal';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {

constructor(public http: Http,public platform: Platform,private oneSignal: OneSignal,public navCtrl: NavController) {

let headers=new Headers();
headers.append('Content-Type','application/json; charset=utf-8');
headers.append('Authorization','Basic NDJhZDg0NWQtYjM0NS00YzUzLTgwNjktMDgyNThlMmUxNDYy')


let url = 'https://onesignal.com/api/v1/notifications';

let body = {
	  app_id: "5d4fd62b-b9f8-4e41-9a89-7ea3b18af3de",
	  contents: {"en": "English Message"},
	  included_segments: ["All"]
	};

let options = new RequestOptions({
	url:url,
	method: "POST",
	body:body,
	headers:headers

})
this.http.post(url, body, options).subscribe(d2=>{
	console.log("success");
	console.log(d2)
})
this.platform.ready().then(() => {
	this.oneSignal.getIds().then((ids)=>{
        console.log("USER ID");
        console.log(ids.userId);
      }).catch((e)=>{
        console.log("error")
        console.log(e);
      })
  	this.oneSignal.startInit('5d4fd62b-b9f8-4e41-9a89-7ea3b18af3de','470761651487');

  	this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);

  	this.oneSignal.handleNotificationReceived().subscribe((d) => {
 		// do something when notification is received
 		console.log("NOTIFICATION RECEIVED");
 		console.log(d);
    });

    this.oneSignal.handleNotificationOpened().subscribe((d1) => {
	  	// do something when a notification is opened
	  	console.log("NOTIFICATOIN OPENED");
	  	console.log(d1);

	});

	this.oneSignal.endInit();
})

}

}


Viewing all articles
Browse latest Browse all 229594

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>