MokoBeacon / mokoBeacon-iOS

iOS SDK
MIT License
4 stars 1 forks source link

Trying SDK in swift #2

Open vegetablesalad opened 5 years ago

vegetablesalad commented 5 years ago

I'm having some issues in replicating code in swift: Am I missing something ?

import mokoBeaconSDK

@objc(BeaconScanner) class BeaconScanner : HCKBeaconCentralManager,HCKCentralScanDelegate {

    func centralManagerScanNewDeviceModel(_ beaconModel: HCKBeaconBaseModel!, manager: HCKBeaconCentralManager!) {
        print("centralManagerScanNewDeviceModel")
    }

    func centralManagerStartScan(_ manager: HCKBeaconCentralManager!){
        print("centralManagerStartScan")
    }

    func centralManagerStopScan(_ manager: HCKBeaconCentralManager!){
        print("centralManagerStopScan")
    }

    public func initialize() {
        print("initialize moko scan")
        let manager = HCKBeaconCentralManager()
        manager.scanDelegate=self
        manager.startScaniBeacons()

    }

}
vegetablesalad commented 5 years ago

Seems that this should be the correct way to go: But it still doesn't return any results

    public func initialize() {
        HCKBeaconCentralManager.sharedInstance().scanDelegate=self
        HCKBeaconCentralManager.sharedInstance().stateDelegate=self
        HCKBeaconCentralManager.sharedInstance().startScaniBeacons()
    }
vegetablesalad commented 5 years ago

As per suggestion I added a delay before scanning. It doesn't resolve the issue:

import mokoBeaconSDK

@objc(BeaconScanner) class BeaconScanner : HCKBeaconCentralManager,HCKCentralStatesChangedDelegate,HCKCentralScanDelegate {

    public func centralManagerStateChanged(_ managerState: HCKBeaconCentralManagerState, manager: HCKBeaconCentralManager!) {
        print(" centralManagerStateChanged")
    }

    public func peripheralConnectStateChanged(_ connectState: HCKBeaconConnectStatus, manager: HCKBeaconCentralManager!) {
        print(" peripheralConnectStateChanged")
    }

    public func centralManagerScanNewDeviceModel(_ beaconModel: HCKBeaconBaseModel!, manager: HCKBeaconCentralManager!) {
        print(" centralManagerScanNewDeviceModel")
    }

    public func centralManagerStartScan(_ manager: HCKBeaconCentralManager!){
        print(" centralManagerStartScan")
    }

    public func centralManagerStopScan(_ manager: HCKBeaconCentralManager!){
        print(" centralManagerStopScan")
    }

    public func initialize() {

        let instance = HCKBeaconCentralManager.sharedInstance()
        instance?.scanDelegate=self
        instance?.stateDelegate=self

        DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
            print(" start scan")
            instance?.startScaniBeacons()
        }

    }

}