Skip to content

Commit

Permalink
feat(ibeacon): using option otherPromise instead of sync (#388)
Browse files Browse the repository at this point in the history
Since the plugin's methods return already a promise, the workaround with the `sync` option was used. This worked well for the method calls. However, when either cordova or the plugin was not available, an error was thrown, instead of rejecting the returned promise.

Therefore a better way is to use the `otherPromise` option, introduced with https://github.com/driftyco/ionic-native/releases/tag/v1.3.8.
  • Loading branch information
Ritzlgrmft authored and ihadeed committed Aug 6, 2016
1 parent b413f21 commit 306cb5d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/plugins/ibeacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the request and started to send events.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static onDomDelegateReady(): Promise<void> { return; }

/**
* Determines if bluetooth is switched on, according to the native layer.
* @returns Returns a promise which is resolved with a {Boolean}
* indicating whether bluetooth is active.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static isBluetoothEnabled(): Promise<boolean> { return; }

/**
Expand All @@ -436,7 +436,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved when Bluetooth
* could be enabled. If not, the promise will be rejected with an error.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static enableBluetooth(): Promise<void> { return; }

/**
Expand All @@ -445,7 +445,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved when Bluetooth
* could be enabled. If not, the promise will be rejected with an error.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static disableBluetooth(): Promise<void> { return; }

/**
Expand All @@ -465,7 +465,7 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the monitoring request.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static startMonitoringForRegion(region: BeaconRegion): Promise<string> { return; }

/**
Expand All @@ -482,7 +482,7 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the request to stop monitoring.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static stopMonitoringForRegion(region: BeaconRegion): Promise<void> { return; }

/**
Expand All @@ -498,7 +498,7 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the request to stop monitoring.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static requestStateForRegion(region: Region): Promise<void> { return; }


Expand All @@ -516,7 +516,7 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the monitoring request.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static startRangingBeaconsInRegion(region: BeaconRegion): Promise<void> { return; }

/**
Expand All @@ -533,7 +533,7 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the request to stop monitoring.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static stopRangingBeaconsInRegion(region: BeaconRegion): Promise<void> { return; }

/**
Expand All @@ -542,7 +542,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved with the
* requested authorization status.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static getAuthorizationStatus(): Promise<any> { return; }

/**
Expand All @@ -554,7 +554,7 @@ export class IBeacon {
* If you are using this plugin on Android devices only, you will never have to use this, nor {@code requestAlwaysAuthorization}
* @returns Returns a promise that is resolved when the request dialog is shown.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static requestWhenInUseAuthorization(): Promise<void> { return; }


Expand All @@ -564,31 +564,31 @@ export class IBeacon {
* @returns Returns a promise which is resolved when the native layer
* shows the request dialog.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static requestAlwaysAuthorization(): Promise<void> { return; }

/**
*
* @returns Returns a promise which is resolved with an {Array}
* of {Region} instances that are being monitored by the native layer.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static getMonitoredRegions(): Promise<Region[]> { return; }

/**
*
* @returns Returns a promise which is resolved with an {Array}
* of {Region} instances that are being ranged by the native layer.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static getRangedRegions(): Promise<Region[]> { return; }

/**
* Determines if ranging is available or not, according to the native layer.
* @returns Returns a promise which is resolved with a {Boolean}
* indicating whether ranging is available or not.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static isRangingAvailable(): Promise<boolean> { return; }

/**
Expand All @@ -600,7 +600,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved with a {Boolean}
* indicating whether the region type is supported or not.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static isMonitoringAvailableForClass(region: Region): Promise<boolean> { return; }

/**
Expand All @@ -620,7 +620,7 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the advertising request.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static startAdvertising(region: Region, measuredPower: number): Promise<void> { return; }

/**
Expand All @@ -631,23 +631,23 @@ export class IBeacon {
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the request to stop advertising.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static stopAdvertising(region: Region): Promise<void> { return; }

/**
* Determines if advertising is available or not, according to the native layer.
* @returns Returns a promise which is resolved with a {Boolean}
* indicating whether advertising is available or not.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static isAdvertisingAvailable(): Promise<boolean> { return; }

/**
* Determines if advertising is currently active, according to the native layer.
* @returns Returns a promise which is resolved with a {Boolean}
* indicating whether advertising is active.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static isAdvertising(): Promise<boolean> { return; }

/**
Expand All @@ -657,7 +657,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved as soon as the
* native layer has set the logging level accordingly.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static disableDebugLogs(): Promise<void> { return; }

/**
Expand All @@ -668,7 +668,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved as soon as the
* native layer has set the flag to enabled.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static enableDebugNotifications(): Promise<void> { return; }

/**
Expand All @@ -678,7 +678,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved as soon as the
* native layer has set the flag to disabled.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static disableDebugNotifications(): Promise<void> { return; }

/**
Expand All @@ -688,7 +688,7 @@ export class IBeacon {
* @returns Returns a promise which is resolved as soon as the
* native layer has set the logging level accordingly.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static enableDebugLogs(): Promise<void> { return; }

/**
Expand All @@ -701,7 +701,7 @@ export class IBeacon {
* message received by the native layer for appending. The returned message
* is expected to be equivalent to the one provided in the original call.
*/
@Cordova({sync: true})
@Cordova({otherPromise: true})
static appendToDeviceLog(message: string): Promise<void> { return; }

}

0 comments on commit 306cb5d

Please sign in to comment.