tuya / tuya-home-ios-sdk-sample-objc

This sample demonstrates how to use Tuya Smart Home iOS SDK features in Objective-C.
https://developer.tuya.com/docs/app-development/ios-app-sdk/feature-overview?id=Ka5cgmlybhjk8
15 stars 10 forks source link

Unable to find Bluetooth Device #15

Closed LiliaRud closed 7 months ago

LiliaRud commented 8 months ago

Hi! I'm developing an app using SDK to control Ambiance Light device. I've cloned this example and wasn't able to find my device through Bluetooth. While with Smart Life app I can find, connect and control it.

Seems like didDiscoveryDeviceWithDeviceInfo doesn't call at all.

I'm adding screen records from both this app and Smart Life app, also adding logs.

My env: iPhone 13 Pro iOS 17.1.2 Xcode 15.2

Logs:

startAuto listening
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
[blekit] -- start scan Scantype:1 cacheStatu:1
ThingBLEScan  ==> BLE Device Start Listening  : discoverServiceUUID 
 service (
) 
 options {
}
[blekit] start connect system (null) <__NSMallocBlock__: 0x281d23090>
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
Connection 6: cleaning up
Connection 6: done
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
ble stop scan clearCache:1

https://github.com/tuya/tuya-home-ios-sdk-sample-objc/assets/17880913/c709bb3c-f3b5-4ccc-aa25-0d60bbbb289e

https://github.com/tuya/tuya-home-ios-sdk-sample-objc/assets/17880913/27458c5f-6e33-4422-b82e-2dd0c6649bf6

All permissions are granted to app: Screenshot 2024-01-11 at 00 20 16 jpeg

Thank you for any help!

taojingGino commented 8 months ago

@LiliaRud pls check this doc,if you add this permission?and Capabilities Access Wi-Fi Information https://developer.tuya.com/en/docs/app-development/ble?id=Ka5vcxzbglphd#title-1-Permissions

LiliaRud commented 8 months ago

@taojingGino yes, all permissions and Capabilities Access Wi-Fi Information are added

Also, just saw this warning. Maybe, it could be connected too? API MISUSE: <CBCentralManager: 0x2801e4a00> has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported

Full logs like this:

[blekit] -- start scan Scantype:1 cacheStatu:1
Bluetooth Background Permission is not enabled in the current application
ThingBLEScan  ==> BLE Device Start Listening  : discoverServiceUUID 
 service (
) 
 options {
}
API MISUSE: <CBCentralManager: 0x2812952c0> has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported
CBCentralManagerStatePoweredOn
ThingBLEScan  ==> BLE Device Start Listening  : discoverServiceUUID 
 service (
) 
 options {
}
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
[blekit] start connect system (null) <__NSMallocBlock__: 0x282df09f0>
ble stop scan clearCache:1

Also, noticed Bluetooth Background Permission is not enabled in the current application but all needed permissions are there

LiliaRud commented 8 months ago

Ok, so I added another permission (which wasn't mentioned in any documentation) and it fixed warnings mentioned above, but it still can't find the device and doesn't trigger didDiscoveryDeviceWithDeviceInfo

<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-central</string>
</array>

Logs:

[blekit] -- start scan Scantype:1 cacheStatu:1
ThingBLEScan  ==> BLE Device Start Listening  : discoverServiceUUID 
 service (
    A201,
    FD50
) 
 options {
    kCBScanOptionAllowDuplicates = 0;
}
CBCentralManagerStatePoweredOn
ThingBLEScan  ==> BLE Device Start Listening  : discoverServiceUUID 
 service (
    A201,
    FD50
) 
 options {
    kCBScanOptionAllowDuplicates = 0;
}
[blekit] start connect system (null) <__NSMallocBlock__: 0x280dd2460>
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
This application is for testing only, but not for commercial use. If the number of registered users reaches the limit, new users cannot be registered.
Connection 1: cleaning up
Connection 3: cleaning up
Connection 1: done
Connection 3: done
ble stop scan clearCache:1
taojingGino commented 8 months ago

pls check this permission

111

Unable to scan Bluetooth devices, it is highly likely that these two permissions were not added @LiliaRud

LiliaRud commented 8 months ago

@taojingGino all permissions are set

    <key>NSBluetoothAlwaysUsageDescription</key>
<string>For Bluetooth scan</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>For Bluetooth scan</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>For Bluetooth scan</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>For Bluetooth scan</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>For Bluetooth scan</string>
<key>UIBackgroundModes</key>
<array>
    <string>bluetooth-central</string>
</array>
taojingGino commented 8 months ago

Everything that needs to be added looks have been added, Can you try another Bluetooth device for testing? We have run our official demo here and can find Bluetooth devices @LiliaRud

LiliaRud commented 7 months ago

@taojingGino as it turned out, I was provided with wrong information and device is Bluetooth Mesh as I figured out by myself. But when I was trying different connection methods from this app, I wasn't able to test SIG Mesh scan as there wasn't implemented createSIGMeshWithHomeId method, so I added it and then was able to find the device.