Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ios - Any way to turn on bluetooth programmatically on iOS7+

I hear that iOS7 introduced this functionality with CBCentralManager but can't find how. Is possible? There is another way widthout use GKPeerPickerController?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can also set the CBCentralManagerOptionShowPowerAlertKey key while instantiating the CBCentralManager to true. Then iOS will show the alert that "Turn On Bluetooth to Allow "Your App" to connect to Accessories". This alert will take you directly to the Bluetooth Setting page.

SampleCode In swift:

centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true])

SampleCode In Objective-C:

centralManager = [[CBCentralManager alloc]
                                      initWithDelegate:self 
                                      queue:dispatch_get_main_queue() 
                                      options:@{CBCentralManagerOptionShowPowerAlertKey: @(YES)}];

Happy Coding.. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...