Skip to content

Commit

Permalink
✨ (ios): Setup ios ble transport
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman committed Jan 30, 2025
1 parent b233dbc commit e207534
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apps/mobile/app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "mobile",
"displayName": "Device Management Kit Mobile Sample"
"displayName": "mobile"
}
1 change: 1 addition & 0 deletions apps/mobile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @format
*/

import 'react-native-get-random-values';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
Expand Down
179 changes: 179 additions & 0 deletions apps/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PODS:
- hermes-engine (0.76.6):
- hermes-engine/Pre-built (= 0.76.6)
- hermes-engine/Pre-built (0.76.6)
- MultiplatformBleAdapter (0.2.0)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -1242,6 +1243,96 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-ble-plx (3.4.0):
- DoubleConversion
- glog
- hermes-engine
- MultiplatformBleAdapter (= 0.2.0)
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-get-random-values (1.11.0):
- React-Core
- react-native-safe-area-context (5.1.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- react-native-safe-area-context/common (= 5.1.0)
- react-native-safe-area-context/fabric (= 5.1.0)
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context/common (5.1.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-safe-area-context/fabric (5.1.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- react-native-safe-area-context/common
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- React-nativeconfig (0.76.6)
- React-NativeModulesApple (0.76.6):
- glog
Expand Down Expand Up @@ -1509,6 +1600,72 @@ PODS:
- React-logger (= 0.76.6)
- React-perflogger (= 0.76.6)
- React-utils (= 0.76.6)
- RNGestureHandler (2.22.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNScreens (4.5.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-RCTImage
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNScreens/common (= 4.5.0)
- Yoga
- RNScreens/common (4.5.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-RCTImage
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- SocketRocket (0.7.1)
- Yoga (0.0.0)

Expand Down Expand Up @@ -1550,6 +1707,9 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
- react-native-ble-plx (from `../node_modules/react-native-ble-plx`)
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
Expand Down Expand Up @@ -1577,10 +1737,13 @@ DEPENDENCIES:
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNScreens (from `../node_modules/react-native-screens`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
trunk:
- MultiplatformBleAdapter
- SocketRocket

EXTERNAL SOURCES:
Expand Down Expand Up @@ -1655,6 +1818,12 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
React-microtasksnativemodule:
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
react-native-ble-plx:
:path: "../node_modules/react-native-ble-plx"
react-native-get-random-values:
:path: "../node_modules/react-native-get-random-values"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-nativeconfig:
:path: "../node_modules/react-native/ReactCommon"
React-NativeModulesApple:
Expand Down Expand Up @@ -1709,6 +1878,10 @@ EXTERNAL SOURCES:
:path: build/generated/ios
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNScreens:
:path: "../node_modules/react-native-screens"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

Expand All @@ -1719,6 +1892,7 @@ SPEC CHECKSUMS:
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
hermes-engine: 1949ca944b195a8bde7cbf6316b9068e19cf53c6
MultiplatformBleAdapter: b1fddd0d499b96b607e00f0faa8e60648343dc1d
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
RCTDeprecation: 063fc281b30b7dc944c98fe53a7e266dab1a8706
RCTRequired: 8eda2a5a745f6081157a4f34baac40b65fe02b31
Expand Down Expand Up @@ -1748,6 +1922,9 @@ SPEC CHECKSUMS:
React-logger: d42a53754a7252cc7a851315f0da2e46b450ea92
React-Mapbuffer: 89885d1518433a462fe64b68bf5e097997380090
React-microtasksnativemodule: 36341e09dcd1df535503e6ed2ddf88f10da56d52
react-native-ble-plx: 7a01a7e595504484789ddb1c94dd9643a03e6309
react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbba
react-native-safe-area-context: 0d8827b2420dfb4c8a8e27639585e61b912261be
React-nativeconfig: 539ff4de6ce3b694e8e751080568c281c84903ce
React-NativeModulesApple: 702246817c286d057e23fe4b1302019796e62521
React-perflogger: f260e2de95f9dbd002035251559c13bf1f0643d4
Expand Down Expand Up @@ -1775,6 +1952,8 @@ SPEC CHECKSUMS:
React-utils: 1b14c41c3edf4d96db1247a78e0ad96e7ceea011
ReactCodegen: 0a0eef9c8cd84c932ae1868832086c6441811e84
ReactCommon: 3c1c8c6d777103c0e60e37c6c5f08e828e2a77c9
RNGestureHandler: 7afc0db05cd604c8530dba90d9b453d4d581deab
RNScreens: 4c7d5710e955dcf72c14a546e29744f9e591370b
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: be6f55a028e86c83ae066f018e9b5d24ffc45436

Expand Down
10 changes: 8 additions & 2 deletions apps/mobile/ios/mobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
Expand Down Expand Up @@ -657,7 +660,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/ios/mobile/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Our app uses bluetooth to find, connect and transfer data between different devices</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"pod": "cd ios && bundle exec pod install --repo-update",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@ledgerhq/device-management-kit": "workspace:*",
"@ledgerhq/device-transport-kit-rn-ble": "workspace:*",
"@ledgerhq/device-transport-kit-react-native-ble": "workspace:*",
"@react-navigation/native": "^7.0.14",
"@react-navigation/stack": "^7.1.1",
"react": "18.3.1",
Expand Down Expand Up @@ -41,6 +42,7 @@
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-native-get-random-values": "^1.11.0",
"react-test-renderer": "18.3.1",
"typescript": "5.0.4"
},
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile/src/components/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const HomeScreen: React.FC = () => {
>({});
const [isScanningDevices, setIsScanningDevices] = React.useState(false);
const [sessionId, setSessionId] = React.useState<string | null>(null);

useEffect(() => {
setDevices({});
}, [sessionId]);

const onScan = useCallback(() => {
const obs = dmk.startDiscovering({});
setDevices({});
Expand All @@ -31,12 +33,13 @@ export const HomeScreen: React.FC = () => {
subscription.unsubscribe();
dmk.stopDiscovering();
};
}, [dmk]);
}, [dmk, devices]);

const onStop = () => {
setIsScanningDevices(false);
dmk.stopDiscovering();
};

const onConnect = async (device: DiscoveredDevice) => {
try {
const id = await dmk.connect({device});
Expand Down
10 changes: 5 additions & 5 deletions apps/mobile/src/providers/dmkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DeviceManagementKitBuilder,
WebLogsExporterLogger,
} from '@ledgerhq/device-management-kit';
import {RNBleTransportFactory} from '@ledgerhq/device-transport-kit-rn-ble';
import {RNBleTransportFactory} from '@ledgerhq/device-transport-kit-react-native-ble';

const DmkContext = createContext<DeviceManagementKit | null>(null);
const LogsExporterContext = createContext<WebLogsExporterLogger | null>(null);
Expand Down Expand Up @@ -49,13 +49,13 @@ export const useDmk = (): DeviceManagementKit => {
};

export function useExportLogsCallback() {
const logsExporter = useContext(LogsExporterContext);
if (logsExporter === null) {
const logsExp = useContext(LogsExporterContext);
if (logsExp === null) {
throw new Error(
'useExportLogsCallback must be used within LogsExporterContext.Provider',
);
}
return useCallback(() => {
logsExporter.exportLogsToJSON();
}, [logsExporter]);
logsExp.exportLogsToJSON();
}, [logsExp]);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"transport-web-hid": "pnpm --filter @ledgerhq/device-transport-kit-web-hid",
"transport-web-ble": "pnpm --filter @ledgerhq/device-transport-kit-web-ble",
"transport-mockserver": "pnpm --filter @ledgerhq/device-transport-kit-mockserver",
"transport-rn-ble": "pnpm --filter @ledgerhq/device-transport-kit-react-native-ble",
"flipper": "pnpm --filter @ledgerhq/device-management-kit-flipper-plugin-client",
"sample": "pnpm --filter @ledgerhq/device-management-kit-sample",
"mobile": "pnpm --filter @ledgerhq/device-management-kit-mobile-sample",
Expand Down
Loading

0 comments on commit e207534

Please sign in to comment.