Need Help with Unlocking Smart Lock Device via BLE in iOS App

App development related product technical discussions, including OEM App, App SDK, device control interface development, mini program development and other topics.


Post Reply
abhi165
Posts: 1

Hi everyone,

I have a smart lock device with the device ID d7446bvfiszjytea. I’m trying to add functionality in my iOS app to connect and unlock this device. Below is my current implementation:

Code: Select all

class ConnectionManager: NSObject, ThingSmartBLEManagerDelegate {
    var siteID = Int64()

func start() {
    if !ThingSmartUser.sharedInstance().isLogin {
        ThingSmartUser.sharedInstance().registerAnonymous(withCountryCode: "+91",
                                                          userName: "guest",
                                                          success: {
            self.loginAndFetchSiteDetails()
        })
    } else {
        loginAndFetchSiteDetails()
    }
}

func createSite(siteName: String, geoName: String, rooms: [String], latitude: Double, longitude: Double, completion: @escaping (Int64?) -> Void) {
    ThingSmartHomeManager().addHome(withName: siteName, geoName: geoName, rooms: rooms, latitude: latitude, longitude: longitude, success: { siteId in
        print("Site created successfully with ID: \(siteId)")
        completion(siteId as? Int64)
    }, failure: {
        print("Failed to create site: \($0)")
        completion(nil)
    })
}

func loginAndFetchSiteDetails() {
    let siteName = "MySite"
    let geoName = "MyGeo"
    let rooms = ["Living Room", "Bedroom"]
    let latitude = 37.7749
    let longitude = -122.4194

    createSite(siteName: siteName, geoName: geoName, rooms: rooms, latitude: latitude, longitude: longitude) { siteId in
        if let siteId = siteId {
            self.siteID = siteId
            ThingSmartBLEManager.sharedInstance().startListening(true)
        }
    }
}

func didDiscoveryDevice(withDeviceInfo deviceInfo: ThingBLEAdvModel) {
    ThingBLELockActivator.shared().activeBLELock(deviceInfo,
                                                 siteId: Int64(siteID),
                                                 success: {
        print("Device activated: \($0)")

        // Attempt to unlock the device
        let lockDevice = ThingLockDevice.shared()
        lockDevice.unLock(withSiteId: self.siteID, deviceId: "d7446bvfiszjytea", success: {
            print("Unlock successful")
        }, failure: {
            print("Unlock failed: \($0)")
        })

        // Alternative method
        let ble = ThingSmartBLELockDevice(deviceId: "d7446bvfiszjytea")
        ble?.autoConnect()
        print("BLE connected: \(ble?.isBLEConnected() ?? false)")

        ble?.addMember(withUserName: ThingSmartUser.sharedInstance().userName,
                       allowUnlock: true,
                       timeType: .permanent,
                       effectiveDate: .now,
                       invalidDate: Date() + 10000,
                       success: {
            print("Member added: \($0)")
            ble?.bleUnlock("guest-171839258741392446433", success: {
                print("BLE unlock successful")
            }, failure: {
                print("BLE unlock failed: \($0)")
            })
        }, failure: {
            print("Failed to add member: \($0)")
            ble?.bleUnlock("guest-171839258741392446433", success: {
                print("BLE unlock successful")
            }, failure: {
                print("BLE unlock failed: \($0)")
            })
        })
    }, failure: {
        print("Device activation failed: \($0)")
    })
}
}

I am able to successfully connect and activate the device, but I am having trouble with unlocking it. I’ve tried two methods to unlock the device, but both of them are failing.

Method 1:

Code: Select all

let lockDevice = ThingLockDevice.shared()
lockDevice.unLock(withSiteId: self.siteID, deviceId: "d7446bvfiszjytea", success: {
    print("Unlock successful")
}, failure: {
    print("Unlock failed: \($0)")
})

Method 2:

Code: Select all

let ble = ThingSmartBLELockDevice(deviceId: "d7446bvfiszjytea")
ble?.autoConnect()
ble?.addMember(withUserName: ThingSmartUser.sharedInstance().userName,
               allowUnlock: true,
               timeType: .permanent,
               effectiveDate: .now,
               invalidDate: Date() + 10000,
               success: {
    print("Member added: \($0)")
    ble?.bleUnlock("guest-171839258741392446433", success: {
        print("BLE unlock successful")
    }, failure: {
        print("BLE unlock failed: \($0)")
    })
}, failure: {
    print("Failed to add member: \($0)")
    ble?.bleUnlock("guest-171839258741392446433", success: {
        print("BLE unlock successful")
    }, failure: {
        print("BLE unlock failed: \($0)")
    })
})

Both methods return different errors:

Code: Select all

•	Method 1: API or API version error
•	Method 2: product dp define error, can't find ble_unlock_check、bluetooth_unlock code

Can anyone guide me on how to properly unlock the device? Any help would be greatly appreciated.

sega
Posts: 1

Re: Need Help with Unlocking Smart Lock Device via BLE in iOS App

Have you managed to make any progress on this? I have the same problem...

Post Reply