| 9 | } from "react-native"; |
| 10 | |
| 11 | function getNativeBGGeo() { |
| 12 | // Prefer TurboModule when the new architecture is enabled. |
| 13 | |
| 14 | if (TurboModuleRegistry && typeof TurboModuleRegistry.get === 'function') { |
| 15 | try { |
| 16 | const turbo = TurboModuleRegistry.get('RNBackgroundGeolocation'); |
| 17 | if (turbo) { |
| 18 | return turbo; |
| 19 | } |
| 20 | } catch (e) { |
| 21 | // If Turbo lookup fails for any reason, fall through to classic bridge. |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // Fallback to classic bridge (old architecture). |
| 26 | const legacy = NativeModules && NativeModules.RNBackgroundGeolocation; |
| 27 | if (legacy) { |
| 28 | return legacy; |
| 29 | } |
| 30 | |
| 31 | // If we reach here, the native module is not installed or not linked. |
| 32 | throw new Error( |
| 33 | '[react-native-background-geolocation] Native module "RNBackgroundGeolocation" not found. ' + |
| 34 | 'Make sure the library is properly installed and linked for your platform.' |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | export const RNBackgroundGeolocation = getNativeBGGeo(); |
| 39 | |