Permalink
Browse files

Step 14.4: Implement getNumber with native ionic

  • Loading branch information...
darkbasic committed Jun 2, 2017
1 parent fc5748c commit d9f5a7a313ae91f97effea7e190833a041c4ceb1
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/services/phone.ts
View
@@ -2,13 +2,31 @@ 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) {
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) => {
@@ -44,4 +62,4 @@ export class PhoneService {
});
});
}
}
}

0 comments on commit d9f5a7a

Please sign in to comment.