关于ios:仅当从Xcode运行时,App才会发现蓝牙设备

App discovers bluetooth devices only when ran from Xcode

我正在为Empatica E4腕带使用该项目的分支,并且如果不从Xcode运行该应用程序,就无法使发现设备正常工作。可以使用原始样本项目来复制这种情况。

当我通过Xcode运行项目时,我可以看到附近设备的列表。
但是,当我关闭该应用程序并从手机中跑了进来(而不是在Xcode上单击"播放")时,我看不到任何设备。

我应该在项目上配置某些东西还是拥有开发者帐户?现在,我没有支付开发者帐户,但我想可以在不使用Xcode来运行应用程序的情况下做到这一点。谢谢。

简而言之:我可以在不将手机连接到XCode的情况下打开应用程序,但是当我未连接到XCode时,我无法发现设备。

更多详细信息。
当通过iphone上的Xcode执行时,设备发现工作正常。在日志上,我们可以看到:

1
2
3
4
E4tester    [didUpdate] status 2 ? kBLEStatusScanning
bluetoothd  Received XPC message"CBMsgIdScan" from session"Empatica.E4testerCV-central-313-24"
bluetoothd  Received 'start scan' request without duplicates for all UUIDs from session"Empatica.E4testerCV-central-313-24"
bluetoothd  State of application"Empatica.E4testerCV" is now"foreground-running"

但是。在iPhone上打开应用程序(而不是通过Xcode运行)时,我们将收到以下日志消息:

1
2
3
E4tester    [didUpdate] status 0 ? kBLEStatusNotAvailable
E4tester    Task <EA813C26-F662-461C-8C47-A97FA7E32BA4>.<0> response ended
E4tester    Task <EA813C26-F662-461C-8C47-A97FA7E32BA4>.<0> done using Connection 1

此处的重要细节是kBLEStatusNotAvailable状态,与kBLEStatusScanning形成对比。根据他们的文档,这意味着iOS设备不支持Bluetooth LE,或者Bluetooth LE模块未激活。但是该设备确实支持BT LE并且已启用。

我在他们的存储库中打开了一个问题。


您需要开发者帐户才能在设备中测试Xcode应用。

开发者帐户将提供证书和配置以在设备中运行应用。有2个证书正在开发和分发。

在您的情况下,您没有任何Apple帐户。所以也许您正在使用freee Provisioning

请阅读以下内容以了解免费提供的内容:
在没有Apple开发人员程序或没有越狱的情况下在设备上测试iOS应用

也许免费提供的功能仅限于调试模式*(从xcode运行)


最后,我从Empatica支持团队得到了直接答复,我认为这是完美的,因为我从可靠和/或官方渠道寻求答案。

不过,我还要感谢Antonio的有用回答,以及Scriptable和Hichem的信息。

Empatica E4团队的回答如下:

@carlosvega If you are working with an iPhone with iOS 11 or 12 you
should add the string NSBluetoothPeripheralUsageDescription in the
Info.plist file. The sample code has been created a while ago before
the privacy string was mandatory.
-- Empatica Engineering Team