gpt4 book ai didi

iOS:使用核心蓝牙库从不同的 View Controller 进行通信

转载 作者:行者123 更新时间:2023-11-29 02:20:57 25 4
gpt4 key购买 nike

我正在做核心蓝牙应用程序。并使用 corebluetooth 框架开发了该库。我有 4 个 View Controller 。在第一个 View Controller 中,我有扫描按钮,当我单击扫描按钮时,第二个屏幕会出现扫描设备,这些设备会出现在表格 View 中。当我单击 TableView 外围设备连接并提供其信息(如服务和特性)时。当我回到第一个 View Controller 时,我有一个名为电池状态的按钮,当我单击该按钮时,它应该从连接的第二个 View Controller 调用电池信息外围。以下是我在第二个 View Controller 中的代码

     -(void)viewdidload
{ coreBle = [[CoreBLE alloc] init];
coreBle.delegate = self;
}

以及用于连接设备

        - (IBAction)Go:(id)sender
{
if (periperal==nil) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil
message:@"Select watch to connect"
delegate:self
cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
else{

[coreBle connectToPeripheralAt:[periperal integerValue]];
NSLog(@"peripheral connected is %@",periperal);
HUD.labelText = @"Connecting...";

[HUD showWhileExecuting:@selector(connectingtask) onTarget:self
withObject:nil animated:YES];

}

}

连接外围设备,从索引路径值处选择行,如下所示

    - (void)tableView:(UITableView *)tableView   
didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

deviceselected= [NSString stringWithFormat:@"Table cell pressed.
(%d)", indexPath.row];
periperal=[NSString stringWithFormat:@"%d",indexPath.row];
}

上面的代码用于在第二个 View Controller 中连接外围设备。同一个外围设备应该在第一个 View Controller 中连接。这样我就可以从中检索值。请帮助我

最佳答案

为什么不将 CoreBLE 代码单独移动到新类中的单个实例。而在四个 View Controller 中,只需调用相关方法即可获取有关 CoreBLE 的信息。因为在您的 ui 操作中,您必须遵循四个 View Controller 的顺序。

关于iOS:使用核心蓝牙库从不同的 View Controller 进行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28146105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com