I have an iPhone app (iOS 7.0) which interacts with a Bluetooth 2.1 sensor device via the ExternalAccessory library. If the app gets backgrounded by any of the usual methods (locking, home button, auto-sleep, etc.) it gets a SIGPIPE when it attempts to resume writing to the NSOutputStream found on the EASession the app uses to communicate with the device. I also get an internal error originating from EAOutputStream saying a write error occurred.

From that point on, I'm never able to write to the output stream, which always returns NO for hasSpaceAvailable with a status of 5 (End of Stream Reached).

Of potential interest: the EAAccessory that the EASession points to shows connected: NO, but the one from [[EAAcessoryManager sharedAccessoryManager] connectedAccessories] shows connected: YES. They have identical connectionId properties. The sensor device's link light remains on during this situation and visiting the Settings > Bluetooth screen shows the device as "Connected". Force-quitting the app and restarting is the only way to resume communication.

Does anyone know how I should go about properly handling this? Do I need to send "close" commands to the streams before the app enters the background and "open" them again when it comes back?

有帮助吗?

解决方案

I resolved this issue by closing the streams as part of the backgrounding process. It seems that retaining an EASession across a backgrounding of the app is a bad idea. Even though I didn't get a SIGPIPE, it was replaced with an EXEC_BAD_ACCESS.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top