Skip to content

Commit 36938c2

Browse files
author
Juha Linnanen
committed
Add methods to unbind manager to make it possible to rebind if there is a need to change which type of layouts are to be scanned.
1 parent 5c8dbd6 commit 36938c2

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

android/src/main/java/com/mackentoch/beaconsandroid/BeaconsAndroidModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public void bindManager() {
7878
mBeaconManager.bind(this);
7979
}
8080

81+
@ReactMethod
82+
public void unbindManager() {
83+
mBeaconManager.unbind(this);
84+
}
85+
8186
@ReactMethod
8287
public void addParser(String parser) {
8388
mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(parser));

lib/next/new.module.android.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,34 @@ async function bindManager(): Promise<any> {
9292
return new Promise((resolve, reject) => {
9393
this.bindListener = DeviceEventEmitter.addListener('bindStatus', ({status}) => {
9494
if (status) {
95-
resolve(status)
95+
resolve(status);
9696
}
9797
else {
98-
reject(status)
98+
reject(status);
9999
}
100-
DeviceEventEmitter.removeListener('bindStatus', this.bindListener)
100+
DeviceEventEmitter.removeListener('bindStatus', this.bindListener);
101101
});
102102
BeaconsManager.bindManager();
103-
})
103+
});
104+
}
105+
106+
/**
107+
* unbind the service
108+
*
109+
*/
110+
async function unbindManager(): Promise<any> {
111+
return new Promise((resolve, reject) => {
112+
this.bindListener = DeviceEventEmitter.addListener('bindStatus', ({status}) => {
113+
if (status) {
114+
resolve(status);
115+
}
116+
else {
117+
reject(status);
118+
}
119+
DeviceEventEmitter.removeListener('bindStatus', this.bindListener);
120+
});
121+
BeaconsManager.unbindManager();
122+
});
104123
}
105124

106125
/**
@@ -275,6 +294,7 @@ module.exports = {
275294
detectEddystoneURL,
276295
detectEddystoneEID,
277296
bindManager,
297+
unbindManager,
278298
detectCustomBeaconLayout,
279299
setBackgroundScanPeriod,
280300
setBackgroundBetweenScanPeriod,

0 commit comments

Comments
 (0)