Simply the fastest way to transmit data between iOS/tvOS and OSX

Overview

Build Status CocoaPods Compatible Carthage Compatible codecov.io codebeat badge

DarkLightning

DarkLightning is a lightweight Swift library to allow data transmission between iOS/tvOS devices (Lightning port, Dock connector, USB-C) and OSX (USB) at 480MBit - without jailbreaking your iOS/tvOS device. It uses the usbmuxd service on OSX to open a TCP socket connection to the iOS/tvOS device.

Overview

  1. Features
  2. System requirements
  3. Installation
  4. Usage
  5. Example
  6. License

1. Features

  • iOS/tvOS und OSX implementations to transmit data with up to 480 MBit via USB between iOS/tvOS and OSX
  • Simulator connection for debugging with iOS/tvOS Simulator
  • Information on connected iOS/tvOS devices on OSX
  • Callbacks for newly connected and disconnected iOS/tvOS devices on OSX

2. Requirements

  • iOS 8.0+
  • tvOS 9.0+
  • Mac OS X 10.10+
  • Xcode 8.3

3. Installation

DarkLightning is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DarkLightning"

There are three subspecs included: iOS, tvOS and OSX. CocoaPods automatically selects the correct subspec depending on the platform you are developing for. That means that pod "DarkLightning" and pod "DarkLightning/iOS" have the same effect if you are developing an iOS app.

4. Usage

The basic procedure to open a connection between iOS/tvOS and OSX looks like this:

  1. Start a DevicePort on a port on iOS/tvOS
  2. Discover the device on OSX
  3. Establish a connection to the previously defined port on iOS/tvOS

You can send an arbitrary amount of bytes between iOS/tvOS and OSX. The data are being sent using TCP.

4.1 iOS/tvOS

4.1.1 Initialization

let port = DevicePort(delegate: MyPortDelegate())
port.open()

4.1.2 Receiving Data

public func port(port: DarkLightning.Port, didReceiveData data: OOData) {

}

4.1.3 Sending Data

let data = "Hello World".data(using: .utf8)
port.writeData(data: data!)

4.2 OSX

4.2.1 Initialization

let daemon = USBDaemon(delegate: MyDaemonDelegate(), deviceDelegate: MyDeviceDelegate())
daemon.start()

4.2.2 Device Discovery

As soon as you plug in or out an iOS/tvOS device to your Mac you will receive a callback on the corresponding delegate method (daemon(_:didAttach:) or daemon(_:didDetach:)) of USBDaemon. You will also receive a callback on daemon(_:didAttach:) for every iOS/tvOS device that was already attached to OSX when you started the discovery via daemon.start().

// Called for every device that already is or will be attached to the system

public func daemon(_ daemon: Daemon, didAttach device: Device) {
     
}

// Called for every iOS/tvOS device that has been detached from the system

public func daemon(_ daemon: Daemon, didDetach device: Device) {
        
}

4.2.3 Connections

With the help of a discovered Device you can now establish a connection to your iOS/tvOS app.

device.connect()

When you are done with the connection make sure to close it properly.

device.disconnect()

4.2.4 Receiving Data

public func device(_ device: Device, didReceiveData data: OOData) {
		
}

4.2.3 Sending Data

let data = "Hello World".data(using: .utf8)
device.writeData(data: data!)

5. Example

The Example (see Example folder) is a simple messenger that uses DarkLightning to send text messages from iOS/tvOS to OSX and vice versa.

Note: The iOS/tvOS application needs to be launched before the OSX part. The OSX part will try to connect to the first device that has been attached via USB. If there are no attached devices it tries to connect to the iOS/tvOS Simulator.

6. License

The MIT License (MIT)

Copyright (c) 2017 Jens Meder

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Packets larger than 8192 bytes

    Packets larger than 8192 bytes

    I'm having trouble receiving tagged packets larger than 8192 bytes on the iOS side.

    I'm assuming that once a packet gets larger than that, it gets split up into smaller pieces, which should be handled by JMTaggedPacketProtocol. The problem is that my JMMobileDevicePortDelegate is only receiving one call to didReceiveData and when I send this data to processData() in my JMTaggedPacketProtocol object, it is returning an empty array.

    Shouldn't my JMMobileDevicePortDelegate be receiving multiple calls to didReceiveData if the data is being split up? Then the JMTaggedPacketProtocol object would buffer the partial data until it has enough to reconstruct the packet.

    Any idea what I might be doing wrong? If I send any packets with their data (NSData) less than 8192 bytes, it works fine.

    opened by klanderson 6
  • JMTaggedPacket, writeData, crash for large files more than 100mb.

    JMTaggedPacket, writeData, crash for large files more than 100mb.

    I use JMTaggedPacket to tagged file that I send. First I get data from file like this:

    func sendNetiveMediaFile(it: MediaItem) {
                let mediaURL = root.URLByAppendingPathComponent(it.mediaNativeFilePath)
                if let data = NSFileManager.defaultManager().contentsAtPath(mediaURL.path!) {
                    self.send(data, tag: paket.tag)
                }
            }
    

    then it call write:

     func send(data: NSData, tag: UInt16) {
           let paket = JMTaggedPacket(data: data, andTag: tag)!
           let send = coder.encodePacket(paket)
           usb.writeData(send)
    }
    

    I use different tags that starts from 1 to 65535.

    When JMSocketConnection calls writeData, if file large it crashes with error:

    * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* NSAllocateMemoryPages(104058079) failed' *** First throw call stack: (0x2152db8b 0x20ceadff 0x2152dad1 0x21cec0b1 0x21cc39dd 0x21c92c59 0x21c92b73 0x21ca026f 0x21ce4603 0x21ce4465 0xf0107 0xf7855 0x18e970 0x191ac8 0x193a90 0x190a64 0x1934e0 0x190af4 0x1e21f6c 0x193750 0x190260 0x190344 0x1910b8 0x191140 0x18f6c4 0x1e21f6c 0x18ec80 0x18ed80 0xf7bf3 0x2395ba7 0x2395b93 0x239a659 0x214ef7d5 0x214edccf 0x2143c289 0x2143c07d 0x22a58af9 0x25b672c5 0x18df24 0x210e8873) libc++abi.dylib: terminating with uncaught exception of type NSException

    screen shot 2016-07-08 at 12 47 49 pm

    can you tell me what happens here? I send file from ios to mac and back.

    bug 
    opened by artem-sherbachuk 5
  • Connect more than one ios device to OSX

    Connect more than one ios device to OSX

    Hi, great work. Is there way to connect two ios devices to OSX and recognize where is first and where is second, I need to make app bundle source synchronization between two ios devices through USB connected to OSX. I need to sync, video and images. is there possible? thank you very much.

    opened by artem-sherbachuk 5
  • JMMobileDevicePort crashes when unplugging USB while writing data

    JMMobileDevicePort crashes when unplugging USB while writing data

    I'm using writeData() on a JMMobileDevicePort instance once every 0.01 seconds. However, when I disconnect the USB device, the connection is being disrupted at the same time it writes the data, and the app crashes. Is a workaround or a fix possible for this?

    bug 
    opened by kirankunigiri 3
  • Connect iOS Device to Apple TV

    Connect iOS Device to Apple TV

    I tried to connect my iPhone to the Apple TV using a USB-C to lightning cable, but it wasn't working.

    Would it be theoretically possible to add this to the library? I read that this library is made by using a program that runs on these devices to have an interface for iOS/tvOS device, but I question if it's possible to use this interface between these devices as well.

    opened by tomgekeerd 1
  • Memory leak when stopping and starting JMUSBDeviceManager

    Memory leak when stopping and starting JMUSBDeviceManager

    To get around the fact that the iOS app needs to be started before the OSX App, I created a timer that runs every second and stops and starts the JMUSBDeviceManager. Although this solution works, the app gradually increases its memory use to the point where it freezes and crashes.

    I have tried de-initializing the JMUSBDeviceManager and creating a new one, along with the JMUSBDevice, and disconnecting and de-initializing the JMUSBDeviceConnection during each restart. However, the memory use stays the same and always crashes.

    Is there a better way to allow the apps to connect no matter which one is first? And is the memory problem due to how I am handling them, or is it a problem within the classes themselves?

    bug 
    opened by kirankunigiri 1
  • General improvements

    General improvements

    Hi @jensmeder,

    I've been working on some improvements that fixes a series of issues I've had when tried to start using the library.

    • Fill all the context's struct members with 0 together with the reference to self.
    • Set DeviceConnection to TCP mode before setting the state to Connected.
    • Improvements in error reporting.

    Let me know if you prefer individual pull requests per feature, and/or the creation of issues for all of them.

    Thanks for the amazing work of putting all this together! Let me know if there's an specific path you want to be followed, I'd love to put some hours in this library.

    Cheers.

    opened by gonzalolarralde 1
  • [Enhancement] Add ability to get iOS device's name

    [Enhancement] Add ability to get iOS device's name

    For example, the device name I have for my iPhone is "Ander's iPhone 6S". I would like JMUSBDevice to have a property called name or something where I can get this information. I know this is possible as this is implemented in Saurik's Cydia Impactor. When you plug your iPhone into your Mac, Cydia Impactor will tell you your device's name (e.g. "Ander's iPhone 6S") and serial number. It is able to do read the device name even on stock iOS devices.

    opened by andermoran 1
  • Max speed bottleneck for multiple devices

    Max speed bottleneck for multiple devices

    My use-case for this framework is to send a large file to batches of devices from a single host. Using the Apple Tetherator utility (Internet sharing over USB), I can send data at ~ 30MB/s to 16 devices using a Thunderbolt usb board (https://cambrionix.com/products/thundersync16-thunderbolt-usb-bridge/).

    Using this framework, I can max the throughput of a single device but am only able to achieve 3.5 MB/s to 16 devices at a time.

    Is this a limitation of usbmuxd or have I missed something?

    My minor changes to your example project are as follows:

    I can loop through a file in blocks of 8192 with a FileHandle and write the data to each device.

    Where 'devices' is an array of connected Device objects and 'data' is a block of 8192 byte data. for device in devices{ device.writeData(data: data) }

    opened by robm92 6
  • Cross-platform version?

    Cross-platform version?

    This project is amazing, but being only available on OSX is a bummer, as usbmuxd is functional on Linux as well. Could you guys consider creating a cross-platform version in Python or Node.js? Thanks!

    enhancement 
    opened by hjstn 3
Releases(2.0.0-alpha1)
  • 2.0.0-alpha1(May 16, 2017)

    What's new

    • Completely rewritten in Swift
    • All new OOP interface with protocols

    Known issues

    • No Objective-C support yet
    • No iOS / tvOS simulator support yet
    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Mar 21, 2017)

  • 1.0.2(Jan 10, 2017)

    Bugfix

    • Fixed a bug that caused JMMobileDevicePort to crash when writing Data while unplugging the iOS device (#34)
    • Fixed a bug that prevented DarkLightning.framework from loading when running on actual iOS device (#36)
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Aug 3, 2016)

    1.0.1

    Bugfix

    • Fixed a bug that caused excessive memory usage when transmitting NSData objects larger than 100MB (thanks to @artem-exd for reporting and fixing)
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jun 26, 2016)

    Additions

    • Added tvOS support (example app comes with the next release)
    • Added support for xcodeproj file generation via phoenx

    Changes

    • Restructured repository
    • Moved build configurations to xcconfig files
    Source code(tar.gz)
    Source code(zip)
  • 0.4.2(Mar 17, 2016)

  • 0.4.1(Dec 5, 2015)

  • 0.4.0(Nov 28, 2015)

    0.4.0

    Additions

    • Added implementation and documentation for JMTaggedPacket and JMTaggedPacketProtocol
    • Added state JMMobileDevicePortStateOpening to JMMobileDevicePort
    • Added return values to close and open methods of JMMobileDevicePort

    Changes

    • Removed JMDataPacketProtocol protocol
    • Example applications now use JMTaggedPacketProtocol
    Source code(tar.gz)
    Source code(zip)
  • 0.3.4(Nov 27, 2015)

  • 0.3.3(Nov 22, 2015)

  • 0.3.2(Nov 22, 2015)

  • 0.3.1(Nov 22, 2015)

    Changes

    • Moved processing of NSStreamDelegate to background thread

    Additions

    • More unit tests added

    Bugfixes

    • Fixed a bug that prevented the JMSocketConnectionConnecting state on JMSocketConnection
    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Nov 20, 2015)

    Additions

    • Added the deviceWithSerialNumber: to JMUSBDeviceManager to obtain a JMUSBDevice for a given serial number if the device is attached to the system.
    • Added more unit tests
    • Added documentation for JMUSBMuxDecoder and JMUSBMuxEncoder
    • Added a state property for JMUSBDeviceManager

    Changes

    • All internal socket code has been refactored and separated in JMSocket, JMHostSocket, JMPathSocket, JMNativeSocket, and JMSocketConnection for reuse
    • All stop and disconnect methods return the value YES from now on
    Source code(tar.gz)
    Source code(zip)
  • 0.2.3(Nov 18, 2015)

  • 0.2.2(Nov 16, 2015)

  • 0.2.1(Nov 15, 2015)

  • 0.2.0(Nov 15, 2015)

    Additions

    • Added examples for iOS and OSX
    • Added a simple packet protocol
    • Added a simulator connection to allow usage of DarkLightning with iOS Simulator

    Changes

    • All connections now run on a separate thread

    Bugfixes

    • Fixed a bug that closed the JMMobileDevicePort or JMUSBChannel connection if an empty NSData object was written to it
    Source code(tar.gz)
    Source code(zip)
  • 0.1.3(Nov 15, 2015)

  • 0.1.2(Nov 2, 2015)

    Fixed

    • Fixed a bug that prevented JMMobileDevicePort to be reopened after a remote connection was closed
    • Fixed an issue where JMUSBDeviceConnection did not report a state change to JMUSBDeviceConnectionStateDisconnected

    Changes

    • JMMobileDevicePort will now close and reopen the underlying socket if a remote USB connection was closed
    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Oct 25, 2015)

    Changelog

    • generics added to JMUSBDeviceManager
    • Improvements in error reporting (thanks to @gonzalolarralde)
    • zero initialisation for internal variables in JMUSBDeviceManager added (thanks to @gonzalolarralde)
    • more documentation added
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Oct 24, 2015)

Owner
Jens Meder
Jens Meder
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, in

EFPrefix 4.3k Jan 2, 2023
iOS & OSX Bluetooth library for RxSwift

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Dec 16, 2022
WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS.

WatchCon WatchCon is a tool which enables creating easy connectivity between iOS and WatchOS Requirements iOS 9.0+ / watchOS 2.0+ CocoaPods CocoaPods

Abdullah Selek 33 Sep 22, 2022
Luminous provides you a lot of information about the system and a lot of handy methods to quickly get useful data on the iOS platform.

Luminous Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 8+ Swift 5 Xcode 1

Andrea Mario Lufino 324 Nov 27, 2022
Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code.

Get the data from Accelerometer, Gyroscope and Magnetometer in only Two or a few lines of code. CoreMotion now made insanely simple :octocat: :satellite:

Muhammad Haroon Baig 1.1k Nov 16, 2022
NFC Forum Well Known Type Data Parser for iOS11 and Core NFC

NFCNDEFParse NFC Forum Well Known Type Data Parser for iOS11 and Core NFC. Supports parsing of types: Text - NFCForum-TS-RTD_Text_1.0 2006-07-24 Uri -

Jari Kalinainen 14 Oct 21, 2022
AirQualityMonitoring - Here display the live air quality monitoring data

AirQualityMonitoring Here display the live air quality monitoring data. Details

MdNiks 0 Jan 28, 2022
AmiiboReader - Reading data from amiibo by using Core NFC

AmiiboReader Reading data from amiibo by using Core NFC NTAG215 Data Sheet https

Shinichiro Oba 7 Mar 24, 2022
Library for iOS Camera API. Massively increase performance and ease of use within your next iOS Project.

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales,

CameraKit 628 Dec 27, 2022
Writes twitter and contact (links) to writable nfcs on iPhone 7+ iOS 14+

nfc writer ios app nfc writer app is a hacky fun side project that writes twitter and contact (links) to writable nfcs. runs on iPhone 7+ iOS 14+. joi

Vivian Phung 5 Nov 23, 2022
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Daniele Margutti 3.2k Dec 30, 2022
Instagram-like photo browser and a camera feature with a few line of code in Swift.

NOTE: This project is no longer maintained. We highly recommend YPImagePicker. Fusuma Fusuma is a Swift library that provides an Instagram-like photo

Yuta Akizuki 2.4k Dec 31, 2022
A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

Alex Littlejohn 2k Dec 29, 2022
:mag_right: A simple and beautiful barcode scanner.

Description BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience. Barco

HyperRedink 1.6k Jan 3, 2023
Swift library to easily check the current device and some more info about it.

Usage To run the example project, clone the repo, and run pod install from the Example directory first. let device = Deviice.current device is a Devi

Andrea Mario Lufino 56 Nov 3, 2022
Light weight tool for detecting the current device and screen size written in swift.

Device detect the current  device model and screen size. Installation CocoaPods Device is available through CocoaPods. To install it, simply add the

Lucas Ortis 1.5k Dec 28, 2022
Lightweight Cocoa library for detecting the running device's model and screen size.

Lightweight Cocoa library for detecting the running device's model and screen size. With the newer  devices, developers have more work to do. This li

Sebastian Dobrincu 1.3k Nov 24, 2022
iOS Bluetooth LE framework

Features A futures interface replacing protocol implementations. Timeout for Peripheral connection, Service scan, Service + Characteristic discovery a

Troy Stribling 696 Dec 25, 2022
You will learn how to scan QR code with iOS framework.

QR Code Scanner You will learn how to scan QR code with in iOS without using any library. It is as simple to scan QR code in iOS. In this example, We

Nitin Aggarwal 11 Dec 8, 2022