cordova-plugin-ble-central: iOS crashes when advertising data contains 'kCBAdvDataLeBluetoothDeviceAddress' (was: Terminating app due to uncaught exception 'NSInvalidArgumentException')
I have been working with this library for some time now and had not experienced any problems so far. Until last week, I received an update from iOS (12.2 to 12.3). After this update Im getting the following error message on all variants of my App made with Ionic in combination with this BLE library:
2019-05-20 13:46:32.105034+0200 MyApp[615:55841] Discovered { advertising = { kCBAdvDataIsConnectable = 1; }; id = "F9D8D19F-AB0C-2BB0-86DB-8B02F33FF7BD"; name = "Sjors\U2019s iMac Pro (4)"; rssi = "-53"; } 2019-05-20 13:46:32.161832+0200 MyApp[615:55841] Discovered { advertising = { kCBAdvDataIsConnectable = 1; kCBAdvDataLeBluetoothDeviceAddress = <b2a4763f 76ff01>; kCBAdvDataLocalName = XXXXX; kCBAdvDataServiceUUIDs = ( "C8DFEE02-1BB6-44D6-9842-2FE4A8874768" ); }; id = "FD7E7083-F1B7-0FAC-0CB3-50876382BAE9"; name = XXXXX; rssi = "-59"; } 2019-05-20 13:46:32.162820+0200 MyApp[615:55841] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_NSInlineData)' *** First throw call stack: (0x1c26ce3a8 0x1c18d3d00 0x1c25d3be4 0x1c31ed920 0x1c31f08a8 0x1c31f0a44 0x1c25b2a14 0x1c31efe54 0x1c31f08a8 0x1c31f0a44 0x1c25b2a14 0x1c31efe54 0x1c31f0af4 0x1c25b1d24 0x1c31f0294 0x1c30a3280 0x1c30a2f90 0x10256bee0 0x1025767d4 0x10256b930 0x102548d44 0x1c822ed04 0x1c822fe3c 0x1c823e42c 0x10265b1f8 0x10265c778 0x102664a34 0x102665778 0x102669fb8 0x1c265e024 0x1c2658cd4 0x1c2658254 0x1c4897d8c 0x1ef9a04c0 0x1025446bc 0x1c2114fd8) libc++abi.dylib: terminating with uncaught exception of type NSException
package.json (example project with only BLE module) { “name”: “myApp”, “version”: “0.0.1”, “author”: “Ionic Framework”, “homepage”: “https://ionicframework.com/”, “scripts”: { “ng”: “ng”, “start”: “ng serve”, “build”: “ng build”, “test”: “ng test”, “lint”: “ng lint”, “e2e”: “ng e2e” }, “private”: true, “dependencies”: { “@angular/common”: “^7.2.2”, “@angular/core”: “^7.2.2”, “@angular/forms”: “^7.2.2”, “@angular/http”: “^7.2.2”, “@angular/platform-browser”: “^7.2.2”, “@angular/platform-browser-dynamic”: “^7.2.2”, “@angular/router”: “^7.2.2”, “@ionic-native/ble”: “^5.6.0”, “@ionic-native/core”: “^5.0.0”, “@ionic-native/splash-screen”: “^5.0.0”, “@ionic-native/status-bar”: “^5.0.0”, “@ionic/angular”: “^4.1.0”, “@ionic/pro”: “2.0.4”, “cordova-android”: “7.1.4”, “cordova-ios”: “4.5.5”, “cordova-plugin-ble-central”: “1.2.2”, “cordova-plugin-compat”: “^1.2.0”, “cordova-plugin-device”: “^2.0.2”, “cordova-plugin-ionic-keyboard”: “^2.1.3”, “cordova-plugin-ionic-webview”: “^4.0.1”, “cordova-plugin-splashscreen”: “^5.0.2”, “cordova-plugin-statusbar”: “^2.4.2”, “cordova-plugin-whitelist”: “^1.3.3”, “core-js”: “^2.5.4”, “rxjs”: “~6.5.1”, “tslib”: “^1.9.0”, “zone.js”: “~0.8.29” }, “devDependencies”: { “@angular-devkit/architect”: “~0.13.8”, “@angular-devkit/build-angular”: “~0.13.8”, “@angular-devkit/core”: “~7.3.8”, “@angular-devkit/schematics”: “~7.3.8”, “@angular/cli”: “~7.3.8”, “@angular/compiler”: “~7.2.2”, “@angular/compiler-cli”: “~7.2.2”, “@angular/language-service”: “~7.2.2”, “@ionic/angular-toolkit”: “~1.5.1”, “@types/node”: “~12.0.0”, “@types/jasmine”: “~2.8.8”, “@types/jasminewd2”: “~2.0.3”, “codelyzer”: “~4.5.0”, “jasmine-core”: “~2.99.1”, “jasmine-spec-reporter”: “~4.2.1”, “karma”: “~4.1.0”, “karma-chrome-launcher”: “~2.2.0”, “karma-coverage-istanbul-reporter”: “~2.0.1”, “karma-jasmine”: “~1.1.2”, “karma-jasmine-html-reporter”: “^0.2.2”, “protractor”: “~5.4.0”, “ts-node”: “~8.1.0”, “tslint”: “~5.16.0”, “typescript”: “~3.1.6” }, “description”: “An Ionic project”, “cordova”: { “plugins”: { “cordova-plugin-ble-central”: {}, “cordova-plugin-whitelist”: {}, “cordova-plugin-statusbar”: {}, “cordova-plugin-device”: {}, “cordova-plugin-splashscreen”: {}, “cordova-plugin-ionic-webview”: {}, “cordova-plugin-ionic-keyboard”: {} }, “platforms”: [ “ios” ] } }
If I look at the error message from Xcode, it looks like there is error in JSON format.
'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_NSInlineData)'
- does this have anything to do with our custom BLE devices?
- why has it always worked up to iOS version 12.3
- what can I currently do to get a working version of my app?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 16 (3 by maintainers)
I made a fork here that changes the logic in serializableAdvertisementData() to dump known properties into a fresh dictionary rather than returning a mutated raw advertising data dictionary.
Unfortunately I don’t have a peripheral handy that causes this issue to occur (but getting complaints about one of my company’s apps that uses this plugin).
Anyone with a peripheral exhibiting this behavior willing to test this fork out?
@bluetooth-mdw good tip on the LG TV. I used mine to troubleshoot this problem.
It looks like the offending key is
kCBAdvDataLeBluetoothDeviceAddressis0x1B <<LE Bluetooth Device Address>>according to the GAP advertising data type.1.16.2 goes on to describes the format, which basically says it’s a MAC address and a bit denoting if it’s public or private address. This could be really useful information in apps. Unfortunately the key isn’t public in Advertisement Data Retrieval Keys so accessing it probably constitutes using a private API.
@jospete thanks for the patch. I’ll get a version of it merged in soon
@JacquesBoileau Thanks for the help with testing!
I’ll make a PR to have this merged into the original plugin.
I just placed it at the end of the method. It’s a nasty hack, of that I have no doubt. But it unblocked my progress and is good enough until someone comes up with something better and gets it merged into this repo.