Giter Site home page Giter Site logo

ios-sdk's Introduction

IRKit iOS SDK

IRKit device and SDK(this library) lets you control your home electronics from your iOS devices. IRKit device has a Infrared LED and receiver, and a WiFi module inside. Any device with internet or local wifi connection can use IRKit devices to make it send IR signals.

This library does:

  • provide UIViewController subclasses that wraps complex procedures to connect and learn IR signals from IRKit devices
  • provide a simple interface to send IR signals

Get IRKit Device

see IRKit device

Installing

Use cocoapods
Currently under heavy development.

$ cat podfile
platform :ios, '7.0'
pod 'IRKit', :git => 'https://github.com/irkit/ios-sdk.git'
workspace 'MyApp.xcworkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'

$ pod install

Usage

See Minimal app for a working minimal IR remote controller application.

Include header

#import <IRKit/IRKit.h>

Initialize

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [IRKit startWithAPIKey:@"#{ fill in your apikey }"];
    return YES;
}

Get API key

% curl -d "email={your email}" "http://api.getirkit.com/1/apps"
{"message":"You will receive an email shortly, please click the URL in it to get an apikey"}

and open the URL in the email.

Sending IR signals

IR signal is represented as a IRSignal instance.

[signal sendWithCompletion:^(NSError *error) {
    NSLog(@"sent error: %@", error);
}];

How to get an IRSignal?

You get your first IRSignal by learning it, which means: you point your old infrared remote controller at IRKit device's IR receiver, and press it's button. IRKit device will send it over to your app(with IRKit iOS SDK).

But first, you need to pair with an IRKit device.

// in your main view controller
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // find IRKit if none is known
    if ([IRKit sharedInstance].countOfReadyPeripherals == 0) {
        IRNewPeripheralViewController *vc = [[IRNewPeripheralViewController alloc] init];
        vc.delegate = self;
        [self presentViewController:vc
                           animated:YES
                         completion:^{
                             NSLog(@"presented");
                         }];
    }
}

#pragma mark - IRNewPeripheralViewControllerDelegate

- (void)newPeripheralViewController:(IRNewPeripheralViewController *)viewController
            didFinishWithPeripheral:(IRPeripheral *)peripheral {
    NSLog( @"peripheral: %@", peripheral );

    [self dismissViewControllerAnimated:YES
                             completion:^{
                                 NSLog(@"dismissed");
                             }];
}

When pairing is done, you're ready to learn an IRSignal from it.

IRNewSignalViewController *vc = [[IRNewSignalViewController alloc] init];
vc.delegate = self;
[self presentViewController:vc
                   animated:YES
                 completion:^{
                     NSLog(@"presented");
                 }];

#pragma mark - IRNewSignalViewControllerDelegate

- (void)newSignalViewController:(IRNewSignalViewController *)viewController
            didFinishWithSignal:(IRSignal *)signal {
    NSLog( @"signal: %@", signal );

    if (signal) {
        // successfully learned!
        _signal = signal;
    }
    [self dismissViewControllerAnimated:YES
                             completion:^{
                                 LOG(@"dismissed");
                             }];
}

Collection of multiple IRSignals

Most remote controllers have more than 1 button, so you'll want to manage a collection of IRSignals. IRSignals (with a s postfix) is it.

_signals = [[IRSignals alloc] init];

// and add a signal to the collection
[_signals addSignalsObject:_signal];

// send multiple IRSignal-s sequentially
[_signals sendSequentiallyWithCompletion:^(NSError *error) {
    NSLog( @"sent with error: %@", error );
}];

// and save it in NSUserDefaults
[_signals saveToStandardUserDefaultsWithKey:@"irkit.signals"];

// or load it from NSUserDefaults
[_signals loadFromStandardUserDefaultsKey:@"irkit.signals"];

// or send it elsewhere
NSData *data = [_signals data];

// or as JSON
NSString *json = [_signals JSONRepresentation];

ios-sdk's People

Contributors

mash avatar shu223 avatar

Watchers

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