Skip to content

Commit

Permalink
fix(contacts): fix crash if plugin is unavailable
Browse files Browse the repository at this point in the history
closes #1250
  • Loading branch information
ihadeed committed Mar 24, 2017
1 parent b6d0e31 commit a9a511d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/@ionic-native/plugins/contacts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { CordovaInstance, InstanceProperty, Plugin, getPromise } from '@ionic-native/core';
import { CordovaInstance, InstanceProperty, Plugin, getPromise, InstanceCheck, checkAvailability } from '@ionic-native/core';

declare var window: any,
navigator: any;
Expand Down Expand Up @@ -72,9 +72,12 @@ export class Contact implements IContactProperties {
@InstanceProperty urls: IContactField[];

constructor() {
this._objectInstance = navigator.contacts.create();
if (checkAvailability(navigator.contacts, 'create', 'Contacts') === true) {
this._objectInstance = navigator.contacts.create();
}
}

@InstanceCheck()
clone(): Contact {
let newContact = new Contact();
for (let prop in this) {
Expand All @@ -87,6 +90,7 @@ export class Contact implements IContactProperties {
@CordovaInstance()
remove(): Promise<any> { return; }

@InstanceCheck()
save(): Promise<any> {
return getPromise((resolve, reject) => {
this._objectInstance.save((contact) => {
Expand Down

0 comments on commit a9a511d

Please sign in to comment.