2016年7月18日 星期一

Estimote SDK: Building a beacon iOS app ---- 1/3

since: 2016/07/18
update: 2016/07/30

reference:
1. Beacon Tech Overview - Estimote Developer

Part 1: Setting up

A. Create a beacon project
    1. iOS > Application > Single View Application > Next

    2. Language: Swift > Next

    3. 設定 iOS 的版本需求: (至少 8.0 以上)
        Airport(Project) > General > Deployment Target: 8.0

-----------------------------------------------------------------------------------------------

B. Add Estimote SDK
    1. 下載: Estimote iOS SDK
         將下載的 iOS-SDK-master.zip 解壓縮後, 在 EstimoteSDK 目錄下可以看到:
         EstimoteSDK.framework 檔案.

    2. 直接將 EstimoteSDK.framework 檔案, 拖拉到專案裡, 並勾選: Copy items if needed

    3. 完成後, 可以看到  EstimoteSDK.framework 已加到專案裡  

-----------------------------------------------------------------------------------------------

C. Add an Objective-C bridging header
     1. Airport(專案目錄) > New File...  

     2. iOS > Source > Header File > Next

     3. Save As: ObjCBridge.h
         > 勾選 Target: Airport(專案目錄)
         > Create

     4. 開啟 ObjCBridge.h 檔案, 修改如下:
#ifndef ObjCBridge_h
#define ObjCBridge_h

//@add ###########################
#import <EstimoteSDK/EstimoteSDK.h>

#endif /* ObjCBridge_h */ 


     5. 設定: Objective-C Bridging Header:
          Airport(Project) > Build Settings >
          Swift Compiler - Code Generation (蠻下面的) > Objective-C Bridging Header
          輸入: ${PROJECT_NAME}/ObjCBridge.h
          備註: 如果
專案名稱更改為中文, 在此要輸入: Airport/ObjCBridge.h

     6. 結果:

-----------------------------------------------------------------------------------------------

D. Add a beacon manager
   1. 開啟 AppDelegate.swift 檔案, 修改如下:
import UIKit

@UIApplicationMain

//@update ################################
//1. Add the ESTBeaconManagerDelegate protocol
//class AppDelegate: UIResponder, UIApplicationDelegate {
class AppDelegate: UIResponder, UIApplicationDelegate, ESTBeaconManagerDelegate {

    var window: UIWindow?
   
    //@add ################################
    // 2. Add a property to hold the beacon manager and instantiate it
    let beaconManager = ESTBeaconManager()

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
       
        //@add ################################
        // 3. Set the beacon manager's delegate
        self.beaconManager.delegate = self
       
        return true
    }


....

-----------------------------------------------------------------------------------------------

E. Authorization to use Location Services
    1. 點選 Info.plist 檔案
       > Add Row:
      Key: NSLocationAlwaysUsageDescription
      Type: String
      Value: (for example:)
      We use low-energy Bluetooth and iBeacon devices installed at the airport to find you inside the hall, and provide relevant information. You don’t need to know security wait times when you’re already at the gate, do you?

    或:
        Key: NSLocationWhenInUsageDescription
        Type: String
        Value: (for example:)
      We use low-energy Bluetooth and iBeacon devices installed at the airport to find you inside the hall, and provide relevant information. You don’t need to know security wait times when you’re already at the gate, do you?

    2. 開啟 AppDelegate.swift 檔案, 修改如下:
....
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
       
        //@add ################################
        // 3. Set the beacon manager's delegate
        self.beaconManager.delegate = self
       
        //@add ################################
        // request the authorization:
        // self.beaconManager.requestWhenInUseAuthorization()

        self.beaconManager.requestAlwaysAuthorization()
       
        return true
    }
....


    3. 第一次執行結果:

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。