Latest 1.2.0
Homepage https://github.com/zoyi/sdk-ibeacon-ios
License SDK
Platforms ios 8.0, requires ARC
Frameworks CoreLocation
Authors

Prerequisites

  • Location Always Usage permission should be enabled(For iBeacon Region monitoring).
  • Device Bluetooth Service should always be active(iBeacon is one of BLE Beacon specs, it needs Bluetooth to work properly).

Integrating ZBeaconKit to your iOS App.

Adding Location Always Usage permission.

Add NSLocationAlwaysUsageDescription key into your project info.plist.

ZBeaconKit

Download ZBeaconKit.framework, and copy to your project root folder.

ZBeaconKit
ZBeaconKit

Drag the ZBeaconKit.framework to your Xcode project path.

ZBeaconKit

Install carthage.

ZBeaconKit

Adding copy file run script.

  • On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script with the following contents:
    /usr/local/bin/carthage copy-frameworks

    and add the paths to the frameworks you want to use under “Input Files”, e.g.:

    $(SRCROOT)/ZBeaconKit.framework

ZBeaconKit

The last step, configure your App specific info.

If you are building with Swift

  • Import ZBeaconKit, configure your App authentication information.
import ZBeaconKit

...

override func viewDidLoad() {
  super.viewDidLoad()

  let manager = Manager(
    email: "[email protected]",
    authToken: "YOUR_AUTH_TOKEN",
    target: .Production // For development, use .Development
  )
  Manager.debugMode = true // For debugging
  Manager.customerId = self.generateSampleCustomerId()

  // You must start manager manually.
  manager.start()

  // And if you want to stop,
  manager.stop()
}

func generateSampleCustomerId() -> String {
  let deviceId = UIDevice.current.identifierForVendor?.uuidString
  let deviceIdWithSalt = deviceId! + "YOUR_SALT"
  return deviceIdWithSalt.hmac(.sha512, key: "YOUR_KEY_FOR_HMAC")
}

If you are building with Objective-C

  • Enable Embedded Content Contains Swift Code flag in Build Settings.

ZBeaconKit

  • Import <ZBeaconKit/ZBeaconKit.h>, configure your App authentication information.

- (void)viewDidLoad {
  [super viewDidLoad];

  self.manager = [[Manager alloc]
                  initWithEmail:@"[email protected]"
                  authToken:@"A1B2C3D4E5F6"
                  target:TargetProduction];  // For development, use TargetDevelopment

  [Manager setDebugMode:true]; // For debugging

  NSString *deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
  NSString *deviceIdWithSalt = [deviceId stringByAppendingString:@"YOUR_SALT"];
  NSString *customerId = [self hmac: deviceIdWithSalt withKey: @"YOUR_KEY_FOR_HMAC"];

  [Manager setCustomerId: customerId];

  // You must start manager manually.
  [self.manager start];

  NSLog(@"%@", [Manager customerId]);
  NSLog(@"%@", [Manager packageId]);

  // And if you want to stop,
  [self.manager stop];
}

- (NSString *) hmac: (NSString *)plaintext withKey:(NSString *)key
  {
    const char *cKey  = [key cStringUsingEncoding:NSASCIIStringEncoding];
    const char *cData = [plaintext cStringUsingEncoding:NSASCIIStringEncoding];
    unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
    CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
    NSData *HMACData = [NSData dataWithBytes:cHMAC length:sizeof(cHMAC)];
    const unsigned char *buffer = (const unsigned char *)[HMACData bytes];
    NSMutableString *HMAC = [NSMutableString stringWithCapacity:HMACData.length * 2];
    for (int i = 0; i < HMACData.length; ++i){
      [HMAC appendFormat:@"%02x", buffer[i]];
    }
    return HMAC;
  }

Deployment Target

Note that you must describe deployment target to manager when initializing.
The deployment target depends on ZOYI’s actual O2O server endpoint.

This flag is only used for mutual test with ZOYI Corp.
So most of 3rd parties does not need to change this.

Case of Swift:

// Set target as PRODUCTION
let manager = Manager(
  email: "...",
  authToken: "...",
  target: .Production
)

// Set target as DEVELOPMENT (signals can not be seen by BLE API)
let manager = Manager(
  email: "...",
  authToken: "...",
  target: .Development
)

Objective-C:

// Set target as PRODUCTION
self.manager = [[Manager alloc]
                initWithEmail:@"..."
                authToken:@"..."
                target:TargetProduction];

// Set target as DEVELOPMENT (signals can not be seen by BLE API)
self.manager = [[Manager alloc]
                initWithEmail:@"..."
                authToken:@"..."
                target:TargetDevelopment];

Latest podspec

{
    "name": "ZBeaconKit",
    "version": "1.2.0",
    "summary": "ZBeaconKit written by ZOYI",
    "description": "ZBeaconKit O2O SDK by ZOYI",
    "homepage": "https://github.com/zoyi/sdk-ibeacon-ios",
    "license": {
        "type": "SDK",
        "file": "LICENSE"
    },
    "authors": {
        "Eng": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/zoyi/sdk-ibeacon-ios.git",
        "tag": "1.2.0"
    },
    "source_files": "ZBeaconKit/",
    "frameworks": "CoreLocation",
    "requires_arc": true
}

Pin It on Pinterest

Share This