Der praktische Alternative zu cordova-plugin-ibeacon für eine Capacitor-App ist @capgo/capacitor-ibeacon. Es deckt dieselben Proximity-Workflows ab wie cordova-plugin-ibeacon (Region Monitoring, Ranging und iOS Advertising) mit Promise-basierten Aufrufen und Capacitor-Event-Listener statt cordova.plugins.locationManager und Delegate-Callbacks. Dieser Guide listet überprüfbare Wartungsfakten, Installationsanweisungen, ein Nutzungssample und eine API-Karte für deinen Umzug von Cordova zu Capacitor.
Warum cordova-plugin-ibeacon in Capacitor verlassen
Das Cordova-Plugin ist auf npm veröffentlicht als cordova-plugin-ibeacon Version 3.8.1. Der Registry- modified Zeitstempel lautet 14. Juni 2022, und die neueste Versionszeile in diesem Paket ist 3.8.1 von 12. Mai 2019. Die Upstream-Quelle befindet sich unter petermetz/cordova-plugin-ibeacon, which documents a LocationManager Fassade beschreibt, die an Apples CLLocationManager.
In einer Capacitor-Codebase trägst du immer noch Cordova-spezifischen Ballast mit dir:
- Installation über
cordova plugin addundcordova.plugins.locationManagerNamespace. BeaconRegionObjekte, die in JavaScript mit Prototype-Helfern des Cordova-Plugins erstellt werden.- Delegate-Events, die über
setDelegateanstatt über Capacitor verdrahtet werdenaddListener.
@capgo/capacitor-ibeacon zielt auf Capacitor 8 mit einer aktiv gepflegten v8-Releaseserie gemäß der Kompatibilitätstabelle im README. Capgo veröffentlicht Issue-Fixes im Open-Source-Takt, bei dem ein Mensch weiterhin täglich 50+ Pull Requests prüft, testet und merged. Das Plugin dokumentiert iOS-Background-Modes, Android-Foreground-Service-Optionen für Background-Scanning auf Android 8+ sowie ARMA-Filter-Helfer, die das Cordova-README für modernes Android nicht abdeckt.
Installieren
bun add @capgo/capacitor-ibeacon
bunx cap sync
iOS: hinzufügen NSLocationWhenInUseUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSBluetoothAlwaysUsageDescription, und die UIBackgroundModes Einträge aus dem Plugin-README. Aktivieren Sie in Xcode die Background-Modes-Fähigkeit für Standort-Updates und Bluetooth-LE-Zubehör, wenn Sie Background-Monitoring benötigen.
Android: das README dokumentiert Background-Scanning über enableBackgroundMode() und optional setBackgroundScanPeriod(). Native-Projekte nach Änderungen an der Capacitor-Konfiguration synchronisieren.
Beispiel für die Verwendung
import { CapacitorIbeacon } from '@capgo/capacitor-ibeacon';
const region = {
identifier: 'StoreFloor',
uuid: 'B9407F30-F5F8-466E-AFF9-25556B57FE6D',
major: 1,
};
export async function watchStore() {
await CapacitorIbeacon.requestWhenInUseAuthorization();
await CapacitorIbeacon.addListener('didEnterRegion', (data) => {
console.log('Entered', data.region.identifier);
});
await CapacitorIbeacon.startMonitoringForRegion(region);
await CapacitorIbeacon.startRangingBeaconsInRegion(region);
}
Migration von Cordova zu Capacitor
Ersetze cordova.plugins.locationManager mit CapacitorIbeacon. Einfache Regionsobjekte übergeben statt new BeaconRegion(...), und abonnieren mit addListener für Events, die zuvor Ihren Delegate erreicht haben.
API-Mapping-Tabelle
cordova-plugin-ibeacon (LocationManager) |
@capgo/capacitor-ibeacon |
|---|---|
new cordova.plugins.locationManager.BeaconRegion(id, uuid, major, minor) |
{ identifier, uuid, major?, minor? } object |
startMonitoringForRegion(region) |
startMonitoringForRegion(options) |
stopMonitoringForRegion(region) |
stopMonitoringForRegion(options) |
startRangingBeaconsInRegion(region) |
startRangingBeaconsInRegion(options) |
stopRangingBeaconsInRegion(region) |
stopRangingBeaconsInRegion(options) |
requestWhenInUseAuthorization() |
requestWhenInUseAuthorization() |
requestAlwaysAuthorization() |
requestAlwaysAuthorization() |
getAuthorizationStatus() |
getAuthorizationStatus() |
startAdvertising(region, measuredPower) |
startAdvertising(options) |
stopAdvertising() |
stopAdvertising() |
isRangingAvailable() |
isRangingAvailable() |
isBluetoothEnabled() |
isBluetoothEnabled() |
Delegieren didEnterRegion |
addListener('didEnterRegion', ...) |
Delegieren didExitRegion |
addListener('didExitRegion', ...) |
Delegieren didRangeBeaconsInRegion |
addListener('didRangeBeacons', ...) |
Delegieren didDetermineStateForRegion |
addListener('didDetermineStateForRegion', ...) |
Capgo ergänzt Android-spezifische Feinjustierungen wie enableARMAFilter() und enableBackgroundMode() die im README des Cordova-Plugins kein direktes Äquivalent haben. Mappen Sie diese, wenn Sie die Hintergrund-Venue-Analyse portieren.
Links und nächste Schritte
- Plugin-Doku: https://capgo.app/docs/plugins/ibeacon/
- Marketing-Seite: /plugins/capacitor-ibeacon/
- npm: https://www.npmjs.com/package/@capgo/capacitor-ibeacon
- GitHub: https://github.com/Cap-go/capacitor-ibeacon/
- Cordova-Upstream: https://github.com/petermetz/cordova-plugin-ibeacon
Änderungen an nativen Berechtigungen oder dem Hintergrundmodus erfordern einen Store-Build. Verwende Capgo Build für Cloud-Binaries und liefere dann UX-Updates mit Capgo Live Updates. Siehe die Cordova- zu Capacitor-Migrationsanleitung für den vollständigen Plattformwechsel.