Beacon SDK - iOS
Guide for iOS Beacon SDK
Prerequisites
Location Always Usagepermission 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 permissions.
Add NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription key into your project info.plist.
Installation
You can install the framework through either cocoapods or carthage.
Cocoapods
Add below into your Podfile
target YOUR_PROJECT_TARGET do
pod 'ZBeaconKit'
end
and run following codes
pod repo update
pod install
Carthage
- Install
carthage. - Add github "zoyi/sdk-ibeacon-ios" to your Cartfile.
- Run carthage update --platform iOS --no-use-binaries.
- Go to your Xcode project's "General" settings. Open
<YOUR_XCODE_PROJECT_DIRECTORY>/Carthage/Checkouts/sdk-ibeacon-iosin Finder and drag ZBeaconKit.framework to the "Embedded Binaries" section in Xcode along with other dependencies. Make sure Copy items if needed is selected and click Finish.

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
Always Embed Swift Standard Librariesflag inBuild Settings. -
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];Updated 8 months ago
