pbakondy / cordova-plugin-sim

:cherries: A cordova plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
MIT License
163 stars 101 forks source link

ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function TypeError: Object(...) is not a function at Sim.getSimInfo #86

Open TonGarcia opened 5 years ago

TonGarcia commented 5 years ago

Expected behaviour

Tell us what should happen.

Actual behaviour

Tell us what happens instead. Provide a log message if relevant

I'm seeing this behaviour on

Remove this hint: these checkboxes can be checked like this: [x]

I am using

Hardware models

Example: Samsung Galaxy S6, iPhone 6s

OS versions

Example: Android 4.4.2, iOS 9.2

I've checked these

So how can we reproduce this?

Provide the used components versions (cordova, ionic, etc).

Provide the steps to reproduce the issue.

Provide files, sources if available.

Complete Error output at device's chrome

vendor.js:1823 ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at Sim.getSimInfo (vendor.js:102391)
    at TimelinePage.webpackJsonp.262.TimelinePage.getDevicePhoneNumber (main.js:1279)
    at TimelinePage.webpackJsonp.262.TimelinePage.ngOnInit (main.js:1291)
    at checkAndUpdateDirectiveInline (vendor.js:12785)
    at checkAndUpdateNodeInline (vendor.js:14309)
    at checkAndUpdateNode (vendor.js:14252)
    at prodCheckAndUpdateNode (vendor.js:14976)
    at Object.eval [as updateDirectives] (ng:///AppModule/TimelinePage_Host.ngfactory.js:11)
    at Object.updateDirectives (vendor.js:14698)
    at Object.checkAndUpdateView (vendor.js:14218)
    at c (polyfills.js:3)
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (vendor.js:5125)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)

App Module

import {Sim} from "@ionic-native/sim/ngx";
providers: [
    Sim
]

Execution Class:

import { Sim } from '@ionic-native/sim/ngx';
constructor(private sim: Sim)

private getDevicePhoneNumber() {
    if(window['cordova']) {
      this.sim.getSimInfo().then(
        (info) => console.log('Sim info: ', info),
        (err) => console.log('Unable to get sim info: ', err)
      );

      this.sim.hasReadPermission().then(
        (info) => console.log('Has permission: ', info)
      );

      this.sim.requestReadPermission().then(
        () => console.log('Permission granted'),
        () => console.log('Permission denied')
      );
    }
  }

  ionViewDidEnter() {
    this.getDevicePhoneNumber();
  }
pbakondy commented 4 years ago

You need to use this this.platform.ready().then(() => { })