diff --git a/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs b/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs
index b647bc1..7deb56b 100644
--- a/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs
+++ b/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs
@@ -42,6 +42,7 @@ public void DidUpdateState(CBCentralManager central)
public void DidConnectPeripheral(CBCentralManager central, CBPeripheral peripheral)
{
Debug.Log($"[DidConnectPeripheral] peripheral: {peripheral}");
+ Debug.Log($"[DidConnectPeripheral] mtu: {peripheral.GetMaximumWriteValueLength(CBCharacteristicWriteType.WithResponse)}");
peripheral.DiscoverServices(new string[] { _serviceUUID });
}
diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Plugins/iOS/CoreBluetoothForUnity.framework/CoreBluetoothForUnity b/Packages/com.teach310.core-bluetooth-for-unity/Plugins/iOS/CoreBluetoothForUnity.framework/CoreBluetoothForUnity
index f90228e..62db518 100755
Binary files a/Packages/com.teach310.core-bluetooth-for-unity/Plugins/iOS/CoreBluetoothForUnity.framework/CoreBluetoothForUnity and b/Packages/com.teach310.core-bluetooth-for-unity/Plugins/iOS/CoreBluetoothForUnity.framework/CoreBluetoothForUnity differ
diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Plugins/macOS/libCoreBluetoothForUnity.dylib b/Packages/com.teach310.core-bluetooth-for-unity/Plugins/macOS/libCoreBluetoothForUnity.dylib
index f095ed3..2a1956f 100755
Binary files a/Packages/com.teach310.core-bluetooth-for-unity/Plugins/macOS/libCoreBluetoothForUnity.dylib and b/Packages/com.teach310.core-bluetooth-for-unity/Plugins/macOS/libCoreBluetoothForUnity.dylib differ
diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheral.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheral.cs
index 299c840..754b7df 100644
--- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheral.cs
+++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheral.cs
@@ -95,6 +95,14 @@ public void WriteValue(byte[] data, CBCharacteristic characteristic, CBCharacter
_nativePeripheral.WriteValue(data, characteristic, type);
}
+ ///
+ /// The maximum amount of data, in bytes, you can send to a characteristic in a single write type.
+ ///
+ public int GetMaximumWriteValueLength(CBCharacteristicWriteType type)
+ {
+ return _nativePeripheral.GetMaximumWriteValueLength(type);
+ }
+
///
/// Sets notifications or indications for the value of a specified characteristic.
///
diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs
index c8443da..2f67bb9 100644
--- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs
+++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs
@@ -132,6 +132,9 @@ internal static extern int cb4u_peripheral_write_characteristic_value(
int writeType
);
+ [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int cb4u_peripheral_maximum_write_value_length(SafeNativePeripheralHandle handle, int writeType);
+
[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]
internal static extern int cb4u_peripheral_set_notify_value(
SafeNativePeripheralHandle handle,
diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativePeripheralProxy.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativePeripheralProxy.cs
index 4fc4702..ab19e0f 100644
--- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativePeripheralProxy.cs
+++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativePeripheralProxy.cs
@@ -106,6 +106,11 @@ internal void WriteValue(byte[] data, CBCharacteristic characteristic, CBCharact
ExceptionUtils.ThrowIfCharacteristicNotFound(result, characteristic.UUID);
}
+ internal int GetMaximumWriteValueLength(CBCharacteristicWriteType writeType)
+ {
+ return NativeMethods.cb4u_peripheral_maximum_write_value_length(_handle, (int)writeType);
+ }
+
internal void SetNotifyValue(bool enabled, CBCharacteristic characteristic)
{
int result = NativeMethods.cb4u_peripheral_set_notify_value(
diff --git a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift
index 480ae0f..e7154d3 100644
--- a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift
+++ b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift
@@ -80,6 +80,10 @@ public class CB4UPeripheral : NSObject {
}
}
+ public func maximumWriteValueLength(_ writeType: CBCharacteristicWriteType) -> Int32 {
+ return Int32(peripheral.maximumWriteValueLength(for: writeType))
+ }
+
public func setNotifyValue(_ serviceUUID: CBUUID, _ characteristicUUID: CBUUID, _ enabled: Bool) -> Int32 {
return actionForCharacteristic(serviceUUID, characteristicUUID) { (service, characteristic) -> Void in
peripheral.setNotifyValue(enabled, for: characteristic)
@@ -97,7 +101,7 @@ extension CB4UPeripheral : CBPeripheralDelegate {
public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
let commaSeparatedServiceIds = peripheral.services?.map { $0.uuid.uuidString }.joined(separator: ",") ?? ""
-
+
commaSeparatedServiceIds.withCString { (commaSeparatedServiceIdsCString) in
didDiscoverServicesHandler?(selfPointer(), commaSeparatedServiceIdsCString, errorToCode(error))
}
@@ -106,7 +110,7 @@ extension CB4UPeripheral : CBPeripheralDelegate {
public func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
let serviceId = service.uuid.uuidString
let commaSeparatedCharacteristicIds = service.characteristics?.map { $0.uuid.uuidString }.joined(separator: ",") ?? ""
-
+
serviceId.withCString { (serviceIdCString) in
commaSeparatedCharacteristicIds.withCString { (commaSeparatedCharacteristicIdsCString) in
didDiscoverCharacteristicsHandler?(selfPointer(), serviceIdCString, commaSeparatedCharacteristicIdsCString, errorToCode(error))
diff --git a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift
index 0c72ca6..614f19a 100644
--- a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift
+++ b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift
@@ -229,6 +229,16 @@ public func cb4u_peripheral_write_characteristic_value(
return instance.writeCharacteristicValue(CBUUID(string: String(cString: serviceUUID)), CBUUID(string: String(cString: characteristicUUID)), data, CBCharacteristicWriteType(rawValue: Int(writeType))!)
}
+@_cdecl("cb4u_peripheral_maximum_write_value_length")
+public func cb4u_peripheral_maximum_write_value_length(
+ _ peripheralPtr: UnsafeRawPointer,
+ _ writeType: Int32
+) -> Int32 {
+ let instance = Unmanaged.fromOpaque(peripheralPtr).takeUnretainedValue()
+
+ return Int32(instance.maximumWriteValueLength(CBCharacteristicWriteType(rawValue: Int(writeType))!))
+}
+
@_cdecl("cb4u_peripheral_set_notify_value")
public func cb4u_peripheral_set_notify_value(
_ peripheralPtr: UnsafeRawPointer,