Jump to content
Sign in to follow this  

Howto call initWithDelegate and CBCentralManagerOptionShowPowerAlertKey

Recommended Posts

Hi there,


I wanted to call the Bluetooth initWithDictionary and its option CBCentralManagerOptionShowPowerAlertKey;

There is little information out there howto create the options for this call in the right way.

  CBCentralManager = interface(NSObject)
    function initWithDelegate(delegate: id; queue: dispatch_queue_t; options: NSDictionary): id; cdecl; overload;

In XCode that looks quite straightforward, but what about Fmx ?

let opts = [CBCentralManagerOptionShowPowerAlertKey: false]
let manager = CBCentralManager(delegate: self, 
                               queue: nil, 
                               options: opts)


Info's like this doesn't help much



Using NSUserDefaults to access the info list properties seems not to work, returning nil.

But is NSUserDefaults the right place to look for those keys ?


    LDefaults: NSUserDefaults; 
    LDict: NSDictionary;       

  LDefaults := TNSUserDefaults.Wrap(TNSUserDefaults.OCClass.standardUserDefaults);
  LDict     := LDefaults.dictionaryForKey( CBCentralManagerOptionShowPowerAlertKey ); // ! This (LDict) is nil

if Assigned(lDict) then
      FCentralManager := TCBCentralManager.Wrap(

I used this function to get the key constant

function CBCentralManagerOptionShowPowerAlertKey : NSString;
  Result := CocoaNSStringConst(libCoreBluetooth, 'CBCentralManagerOptionShowPowerAlertKey');

Other ways to construct this NSDictionary look to ugly to be true:

  LDict     := TNSDictionary.Wrap(
                      <<This is Pointer to object a nil-terminated list>>));


Maybe somebody can help with some useful hints, to find the right way to access such system options  ?


Share this post

Link to post


13 hours ago, Rollo62 said:

Other ways to construct this NSDictionary look to ugly to be true:

They're ugly, but they are true. In your case however you should need only use dictionaryWithObject (since there is only one value), thus:

  LDict: NSDictionary;
  LBooleanValue: Pointer;
  LBooleanValue := TNSNumber.OCClass.numberWithBool(True);
  LDict := TNSDictionary.Wrap(TNSDictionary.OCClass.dictionaryWithObject(LBooleanValue, NSObjectToID(CBCentralManagerOptionShowPowerAlertKey)));


  • Thanks 1

Share this post

Link to post

@Dave Nottage

Thanks, I will check that.

Never know when to use what and why excactly when it comes to iOS objects :classic_smile:


Edited by Rollo62

Share this post

Link to post

Yes it works with that configuration, the LDict is assigned,

and even better, the Bluetooth alert appears.


Thanks again Dave.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this