PhilipsHue / HueSDK

Philips Hue Software Development Kit
99 stars 39 forks source link

Remote connection at iOS #18

Closed rchampa closed 6 years ago

rchampa commented 6 years ago

I have the following swift code:

func buildBridge(info:PHBridgeInfo) -> PHSBridge {

    // Replace app name and device name
    return PHSBridge.init(block: { (builder) in
        builder?.connectionTypes = .remote
        let device = UIDevice.current
        let uid = device.identifierForVendor?.uuidString
        builder?.setupRemote(withAppID: "myapp", withDeviceID: "es.ricardo.com", withAccountGUID: nil, withcallbackURL: "https://localhost", withclientID: "client", withClientSecret: "secret")            

        builder?.bridgeConnectionObserver = self
        builder?.add(self)

    }, withAppName: "MyApp", withDeviceName: "MyDevice")

}

let bridgeInfo:PHBridgeInfo

lazy var bridge:PHSBridge = {

    let b = buildBridge(info:bridgeInfo)
    let brc = b.getConnection(PHSBridgeConnectionType.remote) as! PHSRemoteBridgeConnection

    //this line is not working, url is always an empty string ""
    let url = brc.getLoginURL()
    return b
}()

While in Android the equivalent code is fully working.

bridge = new BridgeBuilder("myapp", Build.MODEL)
    .setConnectionType(BridgeConnectionType.REMOTE)
    .setupRemote(appid, Build.DEVICE, null, "https://localhost", clientid, clientsecret)
    .setBridgeConnectionCallback(bridgeConnectionCallback)
    .addBridgeStateUpdatedCallback(bridgeStateUpdatedCallback)
    .build();
String url = ((RemoteBridgeConnection)bridge.getBridgeConnection(BridgeConnectionType.REMOTE)).getLoginURL();
Log.d(TAG,"URL -> " + url);
webview.loadUrl(url);

Any explanation why brc.getLoginURL() is not working properly at iOS ?

jhvdb87 commented 6 years ago

You are using nil values in the bridge setupRemote method, which results in nil from getLoginURL().