iOS Swift capture network packets - ios

For a testing App i need to get network information from iOS. In Android there are API's available to obtain packets sent, received, size of them in bytes, and some other information. Is there anything similar in Apple iOS?
More deep information obtained with pcap C library can be used without Jailbreak?

More deep information obtained with pcap C library can be used without Jailbreak?
Not by running a libpcap-based program on iOS, because Darwin, by default, makes the BPF devices openable only by root, so, on {OS X, iOS, tvOS} only a process running with root privileges can use libpcap to capture network traffic; without jailbreaking, you can't run a program as root on iOS (or tvOS).
However, with iOS 5 or later, you can use the remote virtual interface facility in iOS and OS X to let a program running on a Mac see the traffic received and sent by an iOS machine.

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.

ios: Communicating between host and USB-Connected device

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

ASCII code on an external device through USB port

Is it possible to send an ASCII code on an external device through USB port using IOS API? I assume that it is possible through bluetooth connection, but I'm not sure through USB connector. Any thoughts?
I would appreciate if someone could put me in the right direction.
Thanking you in advance
That largely depends on the level of sophistication of this "external device". If this external device is just a bare metal embedded device without some sort of operating system you definitely need MFI.
Otherwise, you can run a usbmuxd server (e.g. on Raspberry PI with Linux) to establish a connection via USB. Usbmuxd is basically the technology that Apple uses to communicate between iOS devices and Desktop apps such as iTunes or Xcode. And yes, it is App Store compliant, e.g., Duet Display uses this approach to make an iPad a secondary display for your Desktop via USB.
There are several open source libraries that provide a high level API, e.g., PeerTalk or DarkLightning.

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'.

Resources