【发布时间】:2016-01-28 01:19:48
【问题描述】:
我面临 2 个与常规蓝牙相关的问题。这是我的代码。
- (void)viewDidLoad {
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(showElements) userInfo:nil repeats:NO];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(accessoryConnected:) name:EAAccessoryDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(accessoryDisconnected:) name:EAAccessoryDidConnectNotification object:nil];
[[EAAccessoryManager sharedAccessoryManager]registerForLocalNotifications];
}
-(void)showElements{
[[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error) {
if (error) {
NSLog(@"error :%@", error);
}
else{
NSLog(@"Its Working");
}
}];
}
- (void)accessoryConnected:(NSNotification *)notification
{
EAAccessory *connectedAccessory = [[notification userInfo] objectForKey:EAAccessoryKey];
}
1) 建立连接后出现此错误。
error :Error Domain=EABluetoothAccessoryPickerErrorDomain Code=1 "(null)"
这是完整的日志:-
BTM: attaching to BTServer
BTM: setting pairing enabled
BTM: found device "ESGAA0010" 00:04:3E:95:BF:82
BTM: disabling device scanning
BTM: connecting to device "ESGAA0010" 00:04:3E:95:BF:82
BTM: attempting to connect to service 0x00000080 on device "ESGAA0010" 00:04:3E:95:BF:82
BTM: connection to service 0x00000080 on device "ESGAA0010" 00:04:3E:95:BF:82 succeeded
BTM: setting pairing disabled
error :Error Domain=EABluetoothAccessoryPickerErrorDomain Code=1 "(null)"
你可以看到日志的最后一行,它显示错误。当我搜索并发现苹果文档说错误意味着设备未找到(EABluetoothAccessoryPickerResultNotFound),但是如果未找到它,它如何在日志中显示它已连接。
2) accessoryConnected: 方法没有被调用。它很可能是因为第一个问题。但我认为这里值得一提。
我添加了 ExternalAccessory 框架,并且设备符合 MFI。 帮我解决这些问题。谢谢
【问题讨论】:
-
如果您尝试使用
EAAccessorySelectedKey而不是EAAccessoryKey。不知道什么应该是正确的键,根据文档,一个是显示选择器连接时。此外,您得到的错误输出是在EAAccessory *connectedAccessory行之前或之后? -
@Larme 感谢您的回复,但方法本身没有被调用..那么这似乎不是问题。
-
在什么设备上测试过?什么是iOS版本?
-
我正在 iPhone 6 和 iPhone 5 上分别测试 iOS 9.1 和 iOS 8.4。
-
@Shivaay 我收到此错误错误:Error Domain=EABluetoothAccessoryPickerErrorDomain Code=2 "(null)"
标签: ios objective-c external-accessory mfi