- (void)_writeData {
while (([[_session outputStream] hasSpaceAvailable]) && ([_writeData length] > 0))
{
NSInteger bytesWritten = [[_session outputStream] write:[_writeData bytes] maxLength:[_writeData length]];
if (bytesWritten == -1) {
NSLog(@"write error");
break;
} else if (bytesWritten > 0) {
[_writeData replaceBytesInRange:NSMakeRange(0, bytesWritten) withBytes:NULL length:0];
NSLog(@"bytesWritten %ld", (long)bytesWritten);
}
}
}
I code exactly same as Apple's official demo as above, the communication with external accessory via lightning port works fine except on "iOS 11.2.1".
I debugged and found that it really did the action of sending out data by Outputstream
, but failed anyhow, detect no data out.
anybody know how to find out what's going on inside the stream? is this a bug of Apple?
Finally solved:
1.Hardware side send StatusExternalAccessoryProtocolSession
command as instructed in Accessory Interface Specification R27.pdf
Weird things is that in the version lower than 11.2, the session is able to setup success without this command.