import { Injectable } from '@angular/core' ; import { Platform } from 'ionic-angular' ; import { Sim } from 'ionic-native' ; import { Accounts } from 'meteor/accounts-base' ; import { Meteor } from 'meteor/meteor' ; @ Injectable ( ) export class PhoneService { constructor ( private platform ) { } getNumber ( ) { if ( ! this . platform . is ( 'cordova' ) || ! this . platform . is ( 'mobile' ) ) { return Promise . resolve ( '' ) ; } return Sim . getSimInfo ( ) . then ( ( info ) => { return '+' + info . phoneNumber ; } ) ; } verify ( phoneNumber ) { return new Promise < void > ( ( resolve , reject ) => { Accounts . requestPhoneVerification ( phoneNumber , ( e ) => { if ( e ) { return reject ( e ) ; } resolve ( ) ; } ) ; } ) ; } login ( phoneNumber , code ) { return new Promise < void > ( ( resolve , reject ) => { Accounts . verifyPhone ( phoneNumber , code , ( e ) => { if ( e ) { return reject ( e ) ; } resolve ( ) ; } ) ; } ) ; } logout ( ) { return new Promise < void > ( ( resolve , reject ) => { Meteor . logout ( ( e ) => { if ( e ) { return reject ( e ) ; } resolve ( ) ; } ) ; } ) ; } }