iLocky iOS SDK Usage Manual

This article will teach you how to integrate our iLocky iOS SDK into your app.

Add iLocky.framework into your project

  • In Project Setting -> General  -> Embedded Binaries

螢幕快照 2015-09-26 下午9.53.46

  • If you want to activate the iLocky in background, you should turn on BLE background mode in project setting menu. In Project Setting -> Capabilities  -> Background Modes, turn on Use Bluetooth LE accessories and Acts as a Bluetooth LE accessory.

螢幕快照 2015-09-26 下午7.59.11

To further understand the BLE background mode in iOS, please refer to  Core Bluetooth Background Processing for iOS Apps.

import iLocky in your file

  • in Swift
import iLocky // for v0.2 or earlier
import ilocky // for v1.0 and latter verision
  • in Obj-C
#import "iLocky/ILocky-swift.h"

In AppDelegate.swift/.m (Background Mode)

  • notify iLocky SDK the app is in the foreground or in the background
// in swift
func applicationDidEnterBackground(application: UIApplication) {

func applicationWillEnterForeground(application: UIApplication) {

In ViewController.swift/.m (Foreground Mode & Background Mode)

  • in viewDidLoad(), initialize and load iLocky passports
// in swift
  • Foreground Mode

  • when user intend to access iLocky device, you can start iLocky storyboard. SDK will handle the rest of procedures.


//in Swfit

let frameworkBundle = NSBundle(identifier: "com.ilocky.ILocky")
let sb = UIStoryboard(name:"ILocky",bundle:frameworkBundle)
let vc = sb.instantiateViewControllerWithIdentifier("ILockyViewController")
vc.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
self.presentViewController(vc, animated: true, completion: nil)

螢幕快照 2016-01-07 下午10.38.27.png

developer can get the status if user successfully accesses iLocky device through


  • Background Mode

  • If you want app works in background, you can set delegate when iLocky passport is successfully used or is fail to use, or is not close enough between smart phone and  iLocky device.  In viewDidLoad(), add ILocky.setEventDelegate(ILockyEventDelegate), e.g.
// in swift
there are five delegate functions,onDeviceUnauthorized, onPassportUsed, onILockyAccessSuccess, onILockyAccessFail, and onNotCloseEnough, you can add the corresponding tasks in these delegate functions, e.g.
// in swift
func onDeviceUnauthorized() {
func onPassportUsed(passport:ILockyPassport) {
// when valid passport is found and match the iLocky device,
// this callback is called. It doesn't mean that this passport(key) is ok for this iLocky device.

func onILockyAccessSuccess(passport:ILockyPassport) {
// when successfully use iLocky passport
audioPlayer=try? AVAudioPlayer(contentsOfURL: soundUsePassportSuccess!)
func onILockyAccessFail(passport:ILockyPassport) {
// when fail to use iLocky passport(eg. ble communication error, etc.)

func onNotCloseEnough() {
// when smart phone is not close enough to iLocky device , play the warning sound
audioPlayer=try? AVAudioPlayer(contentsOfURL: soundNotCloseEnough!)


get the uuid of device(phone)

iLocky SDK generate self UUID for identifying the smart phone. To get UUID,you can call
// in swift
return value is represented as string. You can send this return value to iLocky global server through your local server to get the unique key.

import passport to SDK

passport is obtained from iLocky global server, read more on suggested architecture. the typical format of passport is string. When you get the passport string, import it into SDK with ILockyPassport.importPassport function, i.e.
// in swift
ILockyPassport.importPassport(passport:NSString, error:NSErrorPointer)


Change the Language of iLocky Interaction Views

Thre are three languages, English, Traditional Chinese, Simplified Chinsese, can be displayed in our SDK. Our SDK will automatically detect the os language and choose the corresponding language.

The developer still can change the language in our SDK, e.g.

// in swift
ILocky.setLanguage("en")  //show in English
ILocky.setLanguage("zh-Hant")//show in Traditional Chinese
ILocky.setLanguage("zh-Hans") //show in Simplified Chinses


You can refer to our  foreground example and background example

One thought on “iLocky iOS SDK Usage Manual”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s