Permalink
Browse files

Step 14.4: Implement getNumber with native ionic

  • Loading branch information...
darkbasic committed Jun 2, 2017
1 parent f2f2ec6 commit fff952425d3d69935425222b3a02cb530e78be7c
Showing with 23 additions and 0 deletions.
  1. +23 −0 src/services/phone.ts
View
@@ -1,9 +1,32 @@
import { Injectable } from '@angular/core';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import { Platform } from 'ionic-angular';
import { Sim } from '@ionic-native/sim';
@Injectable()
export class PhoneService {
constructor(private platform: Platform,
private sim: Sim) {
}
async getNumber(): Promise<string> {
if (!this.platform.is('cordova')) {
throw new Error('Cannot read SIM, platform is not Cordova.')
}
if (!(await this.sim.hasReadPermission())) {
try {
await this.sim.requestReadPermission();
} catch (e) {
throw new Error('User denied SIM access.');
}
}
return '+' + (await this.sim.getSimInfo()).phoneNumber;
}
verify(phoneNumber: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
Accounts.requestPhoneVerification(phoneNumber, (e: Error) => {

0 comments on commit fff9524

Please sign in to comment.