All along, when using someone else's app, you will often see a "turn on Bluetooth to allow" xxx "connect to Accessories" pop-up box (pictured below),
Click the Settings button to jump to the setting interface of the iOS system.
Then I finally understood what was going on. It was a hint from the iOS system, like using a system album, prompting the user.
Here's how it's implemented.
With the use of Bluetooth, it is necessary to corebluetooth.framework, that is, to add the framework to the project. Then join the Cbcentralmanager class and build delegate.
. h file
#import <CoreBluetooth/CoreBluetooth.h>
@interface mainviewcontroller:uiviewcontroller<cbcentralmanagerdelegate> {
}
@property (nonatomic, strong) Cbcentralmanager *manager;
@end
. m file
@implementation Mainviewcontroller
-(void) Viewdidload {
_manager = [[Cbcentralmanager alloc] initwithdelegate:self Queue:nil]; The point here is to establish a delegate
}
Start viewing the service, Bluetooth turned on
-(void) Centralmanagerdidupdatestate: (Cbcentralmanager *) Central
{
Switch (central.state) {
Case Cbcentralmanagerstatepoweredon:
NSLog (@ "Bluetooth is turned on, please scan peripherals");
Break
Case Cbcentralmanagerstatepoweredoff:
NSLog (@ "Bluetooth off ...");
Break
Default
Break
}
}
In this way, when Bluetooth is off in the setting interface, it will be prompted with the diagram, click "Settings" in the pop-up box and jump to the Bluetooth interface.
Attention:
Be sure if Bluetooth is turned off.
In the same vein, the WiFi interface should be the same principle, but it is unclear which framework is used.