applicationDidEnterBackground
或者applicationWillResignActive
我需要,但我收到startAdvertising
此错误:
CoreBluetooth[API MISUSE] <CBPeripheralManager: 0x146a4e30> can only accept this command while in the powered on state.
我用:
- (void)applicationWillResignActive:(UIApplication *)application
{
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
[_locationManager stopRangingBeaconsInRegion:_runningBeacon];
NSLog(@"stop monitoring");
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"23542266-18D1-4FE4-B4A1-23F8195B9D39"];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:1 minor:1 identifier:@"com.devfright.myRegion"];
self.beaconPeripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:nil];
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil];
[self.peripheralManager startAdvertising:self.beaconPeripheralData];
if ([self.peripheralManager isAdvertising]) {
NSLog(@"peripeheralManager is advertising");
}
}
任何帮助,将不胜感激..