示例#1
0
    void PeripheralScanComplete(string devices)
    {
        var parsedData = JSON.Parse(devices);

        try
        {
            if (parsedData["devices"].Count == 0)
            {
                // Todo : Do something here
                Debug.Log("No devices found.");
                BluetoothInterface.Instance.NoDeviceFound(true);
            }
            else
            {
                for (int i = 0; i < parsedData["devices"].Count; i++)
                {
                    connection.DeviceFound(parsedData["devices"][i]["name"], parsedData["devices"][i]["uuid"]);
                    Debug.Log("Device added: " + parsedData["devices"][i]["name"]);
                }
            }
        } catch (Exception e) {
            if (devices == "NO DEVICE FOUND")
            {
                Debug.Log("No devices found.");
            }
            else
            {
                Debug.LogError("Error when parsing the devices list: " + devices + "\r\n" + e);
            }
        }
        BluetoothInterface.Instance.StopSearching();
    }