Giter Club home page Giter Club logo

apple-family's Introduction

Banner

Apple Family Platform

License MIT Build Passing

A simple framework that brings Apple devices together - like a family. It will automatically use bluetooth, wifi, or USB to connect and communicate with other Apple devices and share information. Currently supports iOS and macOS.

This library is a combination of 2 others I wrote: Apple Signal for wifi and bluetooth communication, and Peertalk Simple for USB communication. Check them out if you only want one of these features.

Demo

Banner

Installation

Grab the files from the source folder and drag them to your project! You also need to have peertalk by Rasmus installed.

Example

Family is simple to setup. Just start the connection, and you can start sending and receiving data! Check out the Xcode demo project for a full implementation .

Setup

Start the connection. Specify a port number, which can be any 4 digit number, and a service type, which is a string limited to 15 characters and 1 hyphen. In order to be discovered, a device must use the same port number and service type. There are also multiple connection types for wifi/bluetooth connectivity. Check the Signal docs for a description of each Signal type.

Family.instance.delegate.addDelegate(delegate: self)
Family.instance.initialize(portNumber: 2345, serviceType: "family-example", signalType: .Automatic)

Next, we also need to run a method in the App Delegate when the app restarts because the usb connection automatically disconnects when the iPhone is put to sleep.

func applicationDidBecomeActive(_ application: UIApplication) {
    Family.instance.reconnect()
}

Send Data

In Family, you can add a tag to the data you send so that the receiver knows what the data is. You can create a UInt32 enum to manage them. Here's an example:

enum DataType: UInt32 {
    case string = 100
    case image = 101
}

Send some text, and specify its type using our enum. Family automatically converts objects to data using NSKeyedArchiver, so if you want to send your own data, use the sendData method instead.

Family.instance.sendObject(object: "Hello World!", type: DataType.string.rawValue)

Receive Data (Protocol)

The protocol conformation. We get the data, check its type, convert it back to the according object, and update our UI. The class has an extension to the Data class - the method convert() - that uses the NSKeyedArchiver class to convert data back into the object you need. You can also update the list of connected devices with the second method.

func family(didReceiveData data: Data, ofType type: UInt32) {
    if type == DataType.string.rawValue {
        let string = data.convert() as! String
    } else if type == DataType.image.rawValue {
        let image = UIImage(data: data)
    }
}

func family(connectedDevicesChanged devices: [String]) {}

And we just setup communication session between devices. It's that simple!

Contribute

Feel free to to contribute to the project with a pull request or open up an issue for any new features or bug fixes.

apple-family's People

Contributors

kirankunigiri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.