[[+content_image]]
Z
Z
Zaur Abdulgalimov2015-12-01 19:14:59
Objective-C
Zaur Abdulgalimov, 2015-12-01 19:14:59

How to reconnect to EAAccessory in iOS?

I am using ExternalAccessory framework in iOS. The first connection works fine:

session = [[EASession alloc] initWithAccessory:self.accessory
                                   forProtocol:@"com.domain.protocol"];
[[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];

Reading the data was also successful . The problem is that if I close the connection:
[[session inputStream] read:buf2 maxLength:1024];
[[session inputStream] setDelegate:nil];
[[session inputStream] removeFromRunLoop:[NSRunLoop currentRunLoop]
                                 forMode:NSDefaultRunLoopMode];
[[session inputStream] close];
//
[[session outputStream] setDelegate:nil];
[[session outputStream] removeFromRunLoop:[NSRunLoop currentRunLoop]
                                 forMode:NSDefaultRunLoopMode];
[[session outputStream] close];

Then after that, when I try to create a new session , I get an error:
ERROR - opening session failed
And the EASession object is not created. Who knows what's the problem?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
German Polyansky, 2015-12-15
@f0r3s1

Well, I don’t know how correctly I understood what you wrote, but you:
firstly, you don’t create, but simply allocate memory for this object and initialize it,
and secondly, how do you create a new session? Do you just need to open the stream? Do simply [[session inputStream] open];
Where in general repeated attempt "to create new session"? If you just run all this code over again, then it will not work, because it allocates memory for an object that is already in memory. take out

session = [[EASession alloc] initWithAccessory:self.accessory
                                   forProtocol:@"com.domain.protocol"];
[[session inputStream] setDelegate:self];
[[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop]
                                 forMode:NSDefaultRunLoopMode];

per function (with outputStream similarly) and should work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question