react-native-ble-plx
react-native-ble-plx copied to clipboard
[iOS][New Architecture][Release] App crash -- TEMPORARY FIX
Hi, In iOS release mode under the new react-native architecture, the app crashes. I've created a temporary patch for this issue.
My versions: "react-native": "0.77.1", "react-native-ble-plx": "^3.5.0",
react-native-ble-plx+3.5.0.patch
diff --git a/node_modules/react-native-ble-plx/ios/BlePlx.m b/node_modules/react-native-ble-plx/ios/BlePlx.m
index 8e0da36..2e28852 100644
--- a/node_modules/react-native-ble-plx/ios/BlePlx.m
+++ b/node_modules/react-native-ble-plx/ios/BlePlx.m
@@ -54,10 +54,14 @@ + (BOOL)requiresMainQueueSetup {
return YES;
}
-RCT_EXPORT_METHOD(createClient:(NSString*)restoreIdentifierKey) {
- _manager = [BleAdapterFactory getNewAdapterWithQueue:self.methodQueue
+RCT_EXPORT_METHOD(createClient:(id)restoreIdentifierKey) {
+ if (restoreIdentifierKey == nil || [restoreIdentifierKey isEqual:[NSNull null]] ||
+ ([restoreIdentifierKey isKindOfClass:[NSString class]] && [(NSString *)restoreIdentifierKey length] == 0)) {
+ restoreIdentifierKey = nil;
+ }
+ _manager = [BleAdapterFactory getNewAdapterWithQueue:dispatch_get_main_queue()
restoreIdentifierKey:restoreIdentifierKey];
- _manager.delegate = self;
+ _manager.delegate = self;
}
RCT_EXPORT_METHOD(destroyClient) {
@@ -97,7 +101,13 @@ - (void)invalidate {
RCT_EXPORT_METHOD(startDeviceScan:(NSArray*)filteredUUIDs
options:(NSDictionary*)options) {
- [_manager startDeviceScan:filteredUUIDs options:options];
+ if (filteredUUIDs == nil || [filteredUUIDs isEqual:[NSNull null]]) {
+ filteredUUIDs = @[];
+ }
+ if (options == nil || [options isEqual:[NSNull null]]) {
+ options = @{};
+ }
+ [_manager startDeviceScan:filteredUUIDs options:options];
}
RCT_EXPORT_METHOD(stopDeviceScan) {
@mario688 this is working great with yarn patch, maybe submit it as a PR so we can get it upstreamed?
What does this patch do? Is it better than disabling new arch for iOS?
Thanks @mario688 this is terrific!
Could it be related to this change in React Native 0.77.1?
Interop Layer: Properly handle null values coming from NativeModules. (475f797a51 by sammy-SC)
@g-otn It looks like it does some basic null-checking of restoreIdentifierKey and filteredUUIDs when starting and scanning, respectively. Overall use and functionality should be unchanged.
Thanks, seems to be working fine with patch-package in my project!
tyyyy
"react-native": "0.79.2"
app crashes
Your are a lifesaver. i struggled 2 3 nights with the ble. i changed many ways in usage of ble plx but it was of no use. app kept crashed in TestFlight. Then i saw the issues and found this fix.
Thanks, I got a crash and don't know what's happening, it's invaluable.
react-native": "0.79.4"
app crashes
I am also affected by this problem.
react-native "0.79.5".
noticed it when I started to have another bluetooth sdk in my app and this at the same time and enabled core-central.
Crashes in 0.79.5 or with Expo 53.
Thank you so much! This patch has fixed an issue where our app wouldn't load on iOS (got stuck on the splash screen). In case it helps anyone, we're using React Native 0.77.1.
@mario688 The patch fixed a crash on Expo for me! Thank you 🙏 Expo v53 React Native v0.79.6 react-native-ble-plx v3.5.0