簡體   English   中英

CBCentralManagerOptionShowPowerAlertKey AlertView /警報控制器“確定”按鈕

[英]CBCentralManagerOptionShowPowerAlertKey AlertView / Alert Controller OK Button

在該應用程序中,我正在使用藍牙低功耗(BLE)技術在兩個不同的iOS設備上創建具有“遙控”功能的視頻播放器,其中一個設備是視頻播放器,另一個設備正在發送消息以進行播放,暫停,快退等我在這里使用CBCentralManagerOptionShowPowerAlertKey創建了中央管理器。

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

如果設備的藍牙設置未打開(我得到的那個具有粗體字體),則將彈出類似於此視圖的警報視圖/警報控制器。

CLBeaconRegion,如何關閉警告:打開藍牙以允許*連接到附件

除了resignFirstResponder之外,我還想向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");
}
  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:@“我的警報”委托:自我cancelButtonTitle:@“ OK” otherButtonTitles:@“取消”,無]顯示]; }}
  4. 在alertView:clikedButtonAtIndex中:您將覆蓋代碼

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM