I am facing 2 problems related to regular Bluetooth.Here is my code.
- (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) I am getting this error after connection got established.
error :Error Domain=EABluetoothAccessoryPickerErrorDomain Code=1 "(null)"
Here is the full log:-
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)"
you can see the last line of log, its showing error. As i searched and found that apple documentation says the error means device not found(EABluetoothAccessoryPickerResultNotFound
), but how come in log it shows its connected if its not found.
2) accessoryConnected:
method not getting called. Its most probably because of first issue. But i thought its worth mentioning here.
I have added ExternalAccessory framework and device is MFI compliant. Help me to fix these. Thanks
EAAccessorySelectedKey
instead ofEAAccessoryKey
. Don't know what should be the correct key, according to the doc, one is when the picker is shown to connect. Also, the error output you get is before of after theEAAccessory *connectedAccessory
line? – Wapentake