I'm using flutter_blue_plus package which is almost same with flutter_blue. When I test with iphone 13 mini connected with mac book xcode, my app scans bluetooth devices well. But when I extract my app to .ipa and install the app using xcode, my iphone 13 mini(which is not connected to mac book) not scan bluetooth devices anymore. Of course I've checked that I give same permission to the iphone both of the test.
Is there any suggestion for test or anyone experienced same situation?
I'm very beginner of flutter and ios development (I just started it from a month ago), so please give me any advice if you have about this bluetooth problem..
My scan function is in the background mode, and I checked the scanned devices using snack bar. But I think it is not the problem, the app works well when I test with xcode and the iphone is connected to mac.
I added a part of my code for your information.
(My function for BLE Scanning)
Future<void> initialScanning() async {
// ios execute this function with .ipa installed but skips scanning.
final FlutterBluePlus flutterBlue = FlutterBluePlus.instance;
// Start scanning
flutterBlue.startScan(timeout: Duration(seconds: _firstScanDuration));
// Listen to scan results
var subscription = flutterBlue.scanResults.listen((results) async {
// Find the device with the name and Register
for (ScanResult r in results) {
print('${r.device.name} rssi: ${r.rssi}');
if (r.device.name == 'raspberrypi') {
if (!devices.contains(r.device)) {
devices.add(r.device);
print('device added!!!!');
}
}
}
for (BluetoothDevice device in devices) {
if (!registeredDevices.contains(device.id.toString())) {
registeredDevices.add(device.id.toString());
await someBleRegister(device);
}
}
});
// Stop scanning
flutterBlue.stopScan();
}
(onEvent
function for flutter_foreground_task
)
@override
Future<void> onEvent(DateTime timestamp, SendPort? sendPort) async {
if (_eventCount == 0) {
await initialScanning();
} else {
print('number of devices: ${someBles.length}');
for (SomeBle ble in someRegisteredBles) {
await someBleReadAndWrite(ble);
}
}