【问题标题】:How to get status for bluetooth privacy setting in iOS6如何在 iOS6 中获取蓝牙隐私设置的状态
【发布时间】:2012-11-26 01:09:23
【问题描述】:

关于iOS6外设蓝牙连接的问题。

如果我在 info.plist 中添加 UIBackgroundModes bluetooth-peripheral,在应用启动时它会首次请求权限。

“appname”希望即使您不使用该应用,也可以让附近的蓝牙设备使用数据

如果我拒绝(不允许)请求,设置-隐私-蓝牙共享-“Appname”变成“OFF”;

我设置监听 CBPeripheralManagerDelegate 以查看是否可以,但即使我拒绝请求,它也总是返回“ON”。 (这也是有道理的,因为它在进入后台之前是“开启”的)

- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{
NSLog(@"%s",__func__);
NSLog(@"%@",[peripheral description]);
NSString *state = nil;
switch (peripheral.state) {
    case CBPeripheralManagerStateResetting:
        state = @"resetting"; break;
    case CBPeripheralManagerStateUnsupported:
        state = @"unsupported"; break;
    case CBPeripheralManagerStateUnauthorized:
        state = @"unauthorized"; break;
    case CBPeripheralManagerStatePoweredOff:
        state = @"off"; break;
    case CBPeripheralManagerStatePoweredOn:
        state = @"on"; break;
    default:
        state = @"unknown"; break;
}
NSLog(@"peripheralManagerDidUpdateState:%@ to %@ (%d)", peripheral, state, peripheral.state);

}

我看到 CBPeripheralManagerStateUnauthorized 看起来像是显示拒绝状态,但即使我拒绝请求,我也无法获得此状态。

问题是: "有什么方法可以查出用户拒绝后台访问请求吗?"

【问题讨论】:

    标签: ios6 core-bluetooth


    【解决方案1】:

    CBPeripheralManager 有一个authorizationStatus 属性,它会报告此信息。 (Apple documentation link)。

    + (CBPeripheralAuthorizationStatus)authorizationStatus

    "返回应用程序在后台状态下共享数据的授权状态。该值指示应用程序是否有权在后台使用蓝牙服务共享数据。有关可能值的列表,请参阅“外设管理器授权状态。”“

    【讨论】:

    • 谢谢。我一直在寻找iOS 6时代,但它终于在iOS 7上实现了。
    猜你喜欢
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多