ios: Communicating between host and USB-Connected device - ios

Android provides "adb" as a mechanism for communicating between host and apps on a USB-connected device. This is useful for automation (e.g. execute some code on the device and collect the results). We need this capability for iOS. Does a similar mechanism exist for iOS?

Yes, there is a similar mechanism. The underlying technology/service is called usbmuxd. It is basically a multiplexing service that allows you to connect to your iOS device via USB using the TCP protocol. Apple uses this service for any communication between your iOS device and iTunes or Xcode, e.g., to install apps via iTunes.
If you want to leverage this mechanism, there is a library that provides a high level API for iOS. They have reverse engineered the whole protocol including things like remote debugging via lldb and app installation.
http://www.libimobiledevice.org
If you just want to sideload compiled binary bundles into your own app you might get away with using my library. It allows you transmit arbitrary data via USB to your app and supports both iOS and tvOS.
http://www.github.com/jensmeder/DarkLightning

Related

Syncing vast amount of test data to iOS device

In an automated test environment, I have to use 7.5GB of test data, that consists of 170k+ files. Simply copying it with the bundle is too slow (40+ minutes), thus I would like to incrementally sync the contents of the test data folder between the iOS device and the mac. Eg. using the iOS device as a USB drive, and use rsync to sync the contents, but any ideas are welcome. No, I can't jailbreak the device. Basically I want to keep two folders synchronized between an iOS test suite and a mac. Any ideas?
There is a way to do that using USB without jailbreaking your iOS device. The whole setup works via a UNIX socket called usbmuxd that Apple uses to communicate between a USB iOS device and e.g. Xcode or iTunes on a Mac. The iOS device basically opens a TCP server and the OSX app connects to the UNIX socket from which it can obtain a TCP connection to server on the iOS device. After that you can just write and read data over USB using streams at 480MBits.
There are some frameworks under MIT license with example apps for OSX and iOS that allow you to use this mechanism in your own apps:
https://github.com/jensmeder/DarkLightning
https://github.com/rsms/peertalk
This mechanism is App Store compliant in case u need to publish your app later. One popular example is an app called Duet Display that allows you to use your iPad as a second screen via USB.
Hope that helps.

Passing objects between different applications

I am trying to develop a Bluetooth Fitness Watch (Bluetooth LE only) as a project of mine. I have created an application (for now we can call it FitX) that allows the user to connect to the watch, similar to the the Pebble Watch, and the object within this app is called fitXWatch (handles the connection and all of that).
However, I now wish to be able to reference this fitXWatch object in another test app so users would be able to integrate my watch into there respective apps. This is the same principal again as Pebble.
I know iOS in general is very sandboxed, but based on Pebble, it gives me hope it can be done.
So my question is this, How can I pass an object from one app to another app similar to Pebble?
Thanks!
According to Apple's Technical Q&A QA1657:
Q: I understand that the External Accessory framework in iOS 3.0 and later will allow my application to communicate with Bluetooth devices. So why doesn't my application see the Bluetooth accessory sitting next to my iPhone?
A: The External Accessory framework is designed to allow iOS applications to communicate only with hardware accessories that are developed under Apple's MFi licensee program. MFi compliant accessories can be implemented as wired devices, meaning they plug in to the Apple device's 30-pin or Lightning connector, or as wireless devices, whereby they use Bluetooth as the communication channel. Either way, an application that uses the External Accessory framework will not be notified of an accessory's presence unless the accessory identifies itself as being MFi compliant, i.e., it was specifically designed to interface with an iOS application.
First of all, are you sure you can't combine the two apps into one single app? Or, maybe convert APP A into a framework and include that framework in APP B?
There is no way to do what you ask locally. You will have to save your object to a file and then upload that file to a remote server. When APP B is opened, it should contact that server and download the file.

Using gPhoto on iOS to communicate with digital cameras over USB

I want bidirectional USB communication between an iOS device and a digital camera using gPhoto2. gPhoto2 "abstracts communication ports and camera protocol, to allow a complete modularity."
Issues I've found:
Apple's strict requirements for apps interfacing with the iOS hardware layer will enviably lead to rejection in the App Store approval process. MFi may mediate this issue.
Getting full access to the lightning/30-pin doc connector to send/receive USB packets may require a private iOS library such as IOKit, and that will get my binary rejected from the App Store.
Connecting a camera via lightning/30-pin launches a PTPCamera-like task to allow the photo app to take over to import photos. That task must be killed get full USB access on OSX, so I'm guessing it's similar on iOS, and killing a task from an app's sandbox seems impossible.
Compiling gPhoto2 for iOS is inherently difficult since I can't dynamically link the gphoto2 library, and thus I must compile it as a static library.
Those are some of the issues I've run into. Is this project worth pursuing? Do you think it's even possible?
Yes, I know there are other solutions, such as using a wifi router or a custom built bluetooth module plugged into the camera to shuttle USB packets to and from the iOS device.

iOS app communicate with an app running in OSX via usb cable connection

Does iOS SDK provide a way to let iOS app talk to app running in OSX/Windows via usb cable connection?
Or, socket is the only option?
If you want to interact with an OS X program from iOS via USB, the PeerTalk lib seems to provide a convenient way to do so (without having to join the MFi program).
According to the github page, PeerTalk
Provides you with USB device attach/detach events and attached device's info
Can connect to TCP services on supported attached devices (e.g. an iPhone), bridging the communication over USB transport
Offers a higher-level API (PTChannel and PTProtocol) for convenient implementations.
[is] Tested and designed for libdispatch (aka Grand Central Dispatch).
It also
has successfully been released on both the iOS and OS X app store.
A great example is Duet Display which is a fantastic piece of software allowing you to use your iDevice as an extra display for your Mac using the Lightning or 30-pin cable. [...]
Communication via USB cable is possible but everything is under strict MFi NDA.
One link that might interest you:
Microchip: 3-step Approach to Develop iPod®, iPhone® and iPad® Accessories
Some more information on Apple MFi program
There are no fees to enter the program but you will have to fill out some 'paperwork'.

What is the mechanism used for having iOS devices communicate with each other?

Is is possible to have two iOS devices talk to each other without having a wireless network present?
If a network is required, can they communicate with each other without having a third device (a web server or something similar) to host the communication?
Yes, they can use Bluetooth or ad-hoc wireless network to the same effect. Apple in fact provides a framework designed to enable this: Game Kit.
See Apple's documentation on the subject for more information.

Resources