关闭EASession问题|外部配件

时间:2017-02-08 16:00:03

标签: ios objective-c bluetooth external-accessory

我打开了一个会话,然后我在不同的线程上打开了输入和输出流。这与EADemo略有不同,因为在EADemo中输入和输出流在主线程上打开。这就是为什么当我在近距离会议时关闭流时,流不会被关闭。

当我关闭会话时,会话未正确关闭,这就是为什么再次打开会话导致以下问题

ERROR - opening session failed ERROR - /BuildRoot/Library/Caches/com.apple.xbs/Sources/ExternalAccessory/ExternalAccessory-353.22.1/EASession.m:-[EASession dealloc] - 141 unable to close session for _accessory=0x170009ee0 and sessionID=65536

我已经读过这个,人们建议,如果流是开放的,那么会话将不会被关闭。因此,要正确关闭会话,请关闭流。

我附上了我的代码图片,如果您还需要代码,请告诉我。

enter image description here

-(void)closeSession { 
    if (_session != nil) {
        sessionOpen = false;
        [[_session inputStream] close];
        [[_session inputStream] removeFromRunLoop:inputRunLoop forMode:NSRunLoopCommonModes];
        [[_session inputStream] setDelegate:nil];

        [[_session outputStream] close];
        [[_session outputStream] removeFromRunLoop:outputRunLoop forMode:NSRunLoopCommonModes];
        [[_session outputStream] setDelegate:nil];
        [_mCommunicationThread cancelThread];
        _mCommunicationThread = nil;
        _session = nil;
        _writeData = nil;
        _readData = nil;
       NSLog(@"session closed"); 
    }
}


-(BOOL)openSession {
    [_accessory setDelegate:self];

    if (_session == nil) {
        _session = [[EASession alloc] initWithAccessory:_accessory forProtocol:_protocolString];
        if (_session) {
            NSLog(@"session created");
            inputReadThread = [[NSThread alloc]initWithTarget:self selector:@selector(inputThreadStart:) object:_session];
            [inputReadThread start];
            [inputReadThread setThreadPriority:1];
            if ([inputReadThread isFinished]) {
             //   NSLog(@"inputReadThread is finished");
            }

            outputThread = [[NSThread alloc]initWithTarget:self selector:@selector(outputThreadStart:) object:_session];
            [outputThread start];
            [outputThread setThreadPriority:1];
            if ([outputThread isFinished]) {
               // NSLog(@"inputReadThread is finished");
            }
        }
        else {
            //NSLog(@"creating session failed");
        }
    }
    return (_session != nil);
}

提前致谢

0 个答案:

没有答案