Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help]: Calling showPowerAlert = false does not prevent app from showing "Turn on Bluetooth to allow .." iOS popup every time #1098

Open
1 task done
spehj opened this issue Jan 15, 2025 · 4 comments
Labels
help Questions, help, observations, or possible bugs

Comments

@spehj
Copy link

spehj commented Jan 15, 2025

Requirements

  • I've looked at the README 'Common Problems' section

Have you checked this problem on the example app?

No

FlutterBluePlus Version

1.34.5

Flutter Version

3.27.1

What OS?

iOS

OS Version

15.8.3 and higher

Bluetooth Module

Don't know

What is your problem?

Bluetooth feature is not mandatory for using our app. However, if we disable Bluetooth in iOS settings (or control panel) we get the popup "Your App would like to use Bluetooth for new connections. You can allow new connections in Settings.".

This happens every time opening the app without BLE turned on. It's annoying for our users.

We set the showPowerAlert option to false right at the start of the app in the Flutter main method, before calling any other FlutterBluePlus method:

Future<void> main() async {
  await FlutterBluePlus.setOptions(showPowerAlert: false);
// Other initializations

}

In the FBP documentation it's said that this needs to be set before any other method of the package:

 /// Set configurable options
  ///   - [showPowerAlert] Whether to show the power alert (iOS & MacOS only). i.e. CBCentralManagerOptionShowPowerAlertKey
  ///       To set this option you must call this method before any other method in this package.
  ///       See: https://developer.apple.com/documentation/corebluetooth/cbcentralmanageroptionshowpoweralertkey
  ///       This option has no effect on Android.

How can this system popup be prevented from being shown every time the app is started?

Example:
anyway-to-stop-the-app-from-asking-for-bluetooth-access-v0-1vnx5nndtm1d1-ezgif com-webp-to-jpg-converter

Logs

No logs since I don't have a MAC right here at the moment.
@spehj spehj added the help Questions, help, observations, or possible bugs label Jan 15, 2025
@spehj
Copy link
Author

spehj commented Jan 15, 2025

Found this answer on StackOverflow:

NSDictionary *options = @{CBCentralManagerOptionShowPowerAlertKey: @NO};
    
_manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
    
[_manager scanForPeripheralsWithServices:nil options:options];

I think this is very similar to the implementation in the FBP native iOS code, where it doesn't work for some reason:

 if (self.centralManager == nil)
        {
            Log(LDEBUG, @"initializing CBCentralManager");

            NSMutableDictionary *options = [NSMutableDictionary dictionary];

            if ([self.showPowerAlert boolValue]) {
                options[CBCentralManagerOptionShowPowerAlertKey] = self.showPowerAlert;
            }

            if ([self.restoreState boolValue]) {
                options[CBCentralManagerOptionRestoreIdentifierKey] = @"flutterBluePlusRestoreIdentifier";
            }

            Log(LDEBUG, @"showPowerAlert: %@", [self.showPowerAlert boolValue] ? @"yes" : @"no");
            Log(LDEBUG, @"restoreState: %@", [self.restoreState boolValue] ? @"yes" : @"no");

            self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
        }

@chipweinberger
Copy link
Owner

chipweinberger commented Jan 20, 2025

need to see these logs

            Log(LDEBUG, @"showPowerAlert: %@", [self.showPowerAlert boolValue] ? @"yes" : @"no");
            Log(LDEBUG, @"restoreState: %@", [self.restoreState boolValue] ? @"yes" : @"no");

@spehj
Copy link
Author

spehj commented Jan 21, 2025

@chipweinberger Here are the logs, when we restart the app (with await FlutterBluePlus.setOptions(showPowerAlert: false);
in the Flutter main method):

[FBP-iOS] handleMethodCall: flutterRestart
[FBP-iOS] initializing CBCentralManager
[FBP-iOS] showPowerAlert: no
[FBP-iOS] restoreState: no
API MISUSE: <CBCentralManager: 0x3025de580> has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported
[FBP-iOS] initializing checkForMtuChangesTimer
[FBP-iOS] disconnectAllDevices(flutterRestart)
[FBP-iOS] connectedPeripherals: 0

Screenshot from Xcode:

Image

@chipweinberger
Copy link
Owner

im not sure why this popup shows. If you figure it out, please let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help Questions, help, observations, or possible bugs
Projects
None yet
Development

No branches or pull requests

2 participants