Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios EAAccessoryManager';中未显示已连接的蓝牙模块;s连接附件_Ios_Objective C_Eaaccessory - Fatal编程技术网

Ios EAAccessoryManager';中未显示已连接的蓝牙模块;s连接附件

Ios EAAccessoryManager';中未显示已连接的蓝牙模块;s连接附件,ios,objective-c,eaaccessory,Ios,Objective C,Eaaccessory,我正在开发一款使用蓝牙2.1的应用程序。每次应用程序激活时,它都会打开一个EASession。每次应用程序转到后台或终止时,EASession都会关闭 如果蓝牙模块已连接,且应用程序已重新启动,则会正常打开,发送/获取数据所有功能正常 但若蓝牙模块在应用程序运行时失去通信,在重新连接并从后台打开应用程序后。缓和开放失败 并且没有列出任何已连接的附件 (eA附件*)选择附件 { } 此处[\u accessoryList count]为0 有人知道发生了什么事吗? 谢谢 编辑: 我运行了更多的

我正在开发一款使用蓝牙2.1的应用程序。每次应用程序激活时,它都会打开一个EASession。每次应用程序转到后台或终止时,EASession都会关闭

如果蓝牙模块已连接,且应用程序已重新启动,则会正常打开,发送/获取数据所有功能正常

但若蓝牙模块在应用程序运行时失去通信,在重新连接并从后台打开应用程序后。缓和开放失败

并且没有列出任何已连接的附件

  • (eA附件*)选择附件
{

}

此处[\u accessoryList count]为0

有人知道发生了什么事吗? 谢谢

编辑:

我运行了更多的测试,这次看起来不同了

- (BOOL)openSession
{
    if (_session == nil)
    {
        NSLog(@"EAController::openSession");
        [_selectedAccessory setDelegate:self];
        _session = [[EASession alloc] initWithAccessory:[self selectedAccessory] forProtocol:_protocolString];

        if (_session)
        {
            [[_session inputStream] setDelegate:self];
            [[_session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
            [[_session inputStream] open];

            [[_session outputStream] setDelegate:self];
            [[_session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
            [[_session outputStream] open];
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setBool:YES forKey:Unit_Has_Connection];
            NSLog(@"opened the session");
        }
        else
        {
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setBool:NO forKey:Unit_Has_Connection];
            NSLog(@"creating session failed");
        }
    }

    return (_session != nil);
}
这一次,selectedAccessory似乎很好。但它不能初始化会话

使用附件行初始化后,打印出错误:

2013-06-17 15:03:39.967 IceMachine[770:60b] ERROR - opening session failed
2013-06-17 15:03:39.968 IceMachine[770:60b] ERROR - /SourceCache/ExternalAccessory/ExternalAccessory-237/EASession.m:-[EASession dealloc] - 139 unable to close session for _accessory=0x15543fe0 and sessionID=65536

您必须手动将_protocolString的值添加到应用程序的info.plist(支持的外部附件协议部分)中

2013-06-17 15:03:39.967 IceMachine[770:60b] ERROR - opening session failed
2013-06-17 15:03:39.968 IceMachine[770:60b] ERROR - /SourceCache/ExternalAccessory/ExternalAccessory-237/EASession.m:-[EASession dealloc] - 139 unable to close session for _accessory=0x15543fe0 and sessionID=65536