0

在应用程序中,我正在使用蓝牙低功耗 (BLE) 使用两个不同的 iOS 设备创建一个带有“远程控制”的视频播放器,其中一个设备是视频播放器,另一个是发送消息以播放、暂停、倒带等. 在这里,我使用 CBCentralManagerOptionShowPowerAlertKey 创建了中央管理器。

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CBCentralManagerOptionShowPowerAlertKey, nil];
        centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil options:options];

如果设备没有打开其蓝牙设置(我得到的那个有粗体),则会弹出一个类似于这个的警报视图/警报控制器。

CLBeaconRegion,如何关闭警告:打开蓝牙允许*连接到附件

我想在按下除 resignFirstResponder 之外的 OK 按钮时添加更多功能。

我缺少什么需要修改此警报视图/警报控制器中的 OK 按钮的功能?我已经断点并记录了方法,但仍然未能捕捉到:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"Button Index =%ld",(long)buttonIndex);
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"%ld", (long)buttonIndex);
}

-(void)alertViewCancel:(UIAlertView *)alertView
{
    NSLog(@"alert view cancel");
}
4

1 回答 1

1
  1. 您需要更改 centralManager 的选项,形成 [NSNumber numberWithBool:YES]; 到 [NSNumber numberWithBool:NO];
  2. 使用 centralManagerDidUpdateState: 方法实现 CBCentralManagerDeletgate。
  3. 在 centralManagerDidUpdateState: 方法中,您将创建 alertview

    • (void)centralManagerDidUpdateState:(CBCentralManager *)central { if (_bluetoothManager.state == CBCentralManagerStatePoweredOff) { [[[UIAlertView alloc] initWithTitle:nil message:@"my alert" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"取消", nil ] 显示]; } }
  4. 在 alertView:clikedButtonAtIndex: 您将覆盖您的代码

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"%ld", (long)buttonIndex); }

于 2015-09-25T08:32:28.130 回答