diff --git a/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs b/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs index 0dbfa60..2e97394 100644 --- a/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs +++ b/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Central.cs @@ -150,6 +150,11 @@ public void DidReadRSSI(CBPeripheral peripheral, int rssi, CBError error) } } + public void DidUpdateName(CBPeripheral peripheral) + { + Debug.Log($"[DidUpdateName] {peripheral}"); + } + public void OnClickWrite() { if (_peripheral == null) 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 1efbd65..fc4a0b9 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 a14f60c..c153b56 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 41998d7..5885822 100644 --- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheral.cs +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheral.cs @@ -22,6 +22,7 @@ void DidWriteValueForCharacteristic(CBPeripheral peripheral, CBCharacteristic ch void IsReadyToSendWriteWithoutResponse(CBPeripheral peripheral) { } void DidUpdateNotificationStateForCharacteristic(CBPeripheral peripheral, CBCharacteristic characteristic, CBError error) { } void DidReadRSSI(CBPeripheral peripheral, int rssi, CBError error) { } + void DidUpdateName(CBPeripheral peripheral) { } } /// @@ -247,6 +248,12 @@ void INativePeripheralDelegate.DidReadRSSI(int rssi, CBError error) Delegate?.DidReadRSSI(this, rssi, error); } + void INativePeripheralDelegate.DidUpdateName() + { + if (_disposed) return; + Delegate?.DidUpdateName(this); + } + public override string ToString() { return $"CBPeripheral: identifier = {Identifier}, name = {Name}, state = {State}"; 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 3b9e215..aec1c8d 100644 --- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs @@ -77,6 +77,7 @@ int serviceUUIDsCount internal delegate void CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler(IntPtr peripheralPtr); internal delegate void CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler(IntPtr peripheralPtr, IntPtr serviceUUIDPtr, IntPtr characteristicUUIDPtr, int notificationState, int errorCode); internal delegate void CB4UPeripheralDidReadRSSIHandler(IntPtr peripheralPtr, int rssi, int errorCode); + internal delegate void CB4UPeripheralDidUpdateNameHandler(IntPtr peripheralPtr); [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)] internal static extern void cb4u_peripheral_register_handlers( @@ -87,7 +88,8 @@ internal static extern void cb4u_peripheral_register_handlers( CB4UPeripheralDidWriteValueForCharacteristicHandler didWriteValueForCharacteristicHandler, CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler isReadyToSendWriteWithoutResponseHandler, CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler didUpdateNotificationStateForCharacteristicHandler, - CB4UPeripheralDidReadRSSIHandler didReadRSSIHandler + CB4UPeripheralDidReadRSSIHandler didReadRSSIHandler, + CB4UPeripheralDidUpdateNameHandler didUpdateNameHandler ); [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)] diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralHandle.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralHandle.cs index ba6cc96..85b5603 100644 --- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralHandle.cs +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralHandle.cs @@ -13,6 +13,7 @@ void DidWriteValueForCharacteristic(string serviceUUID, string characteristicUUI void IsReadyToSendWriteWithoutResponse() { } void DidUpdateNotificationStateForCharacteristic(string serviceUUID, string characteristicUUID, bool enabled, CBError error) { } void DidReadRSSI(int rssi, CBError error) { } + void DidUpdateName() { } } internal class SafeNativePeripheralHandle : SafeHandle @@ -36,7 +37,8 @@ void RegisterHandlers() DidWriteValueForCharacteristic, IsReadyToSendWriteWithoutResponse, DidUpdateNotificationStateForCharacteristic, - DidReadRSSI + DidReadRSSI, + DidUpdateName ); } @@ -141,5 +143,11 @@ internal static void DidReadRSSI(IntPtr peripheralPtr, int rssi, int errorCode) CBError.CreateOrNullFromCode(errorCode) ); } + + [AOT.MonoPInvokeCallback(typeof(NativeMethods.CB4UPeripheralDidUpdateNameHandler))] + internal static void DidUpdateName(IntPtr peripheralPtr) + { + GetDelegate(peripheralPtr)?.DidUpdateName(); + } } } diff --git a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift index 37788f6..4b18161 100644 --- a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift +++ b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheral.swift @@ -10,6 +10,7 @@ public class CB4UPeripheral : NSObject { public var isReadyToSendWriteWithoutResponseHandler: CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler? public var didUpdateNotificationStateForCharacteristicHandler: CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler? public var didReadRSSIHandler: CB4UPeripheralDidReadRSSIHandler? + public var didUpdateNameHandler: CB4UPeripheralDidUpdateNameHandler? let success: Int32 = 0 let serviceNotFound: Int32 = -2 @@ -173,4 +174,8 @@ extension CB4UPeripheral : CBPeripheralDelegate { public func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) { didReadRSSIHandler?(selfPointer(), Int32(RSSI.intValue), errorToCode(error)) } + + public func peripheralDidUpdateName(_ peripheral: CBPeripheral) { + didUpdateNameHandler?(selfPointer()) + } } diff --git a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift index 3acd57a..b4a6d66 100644 --- a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift +++ b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift @@ -119,6 +119,7 @@ public typealias CB4UPeripheralDidWriteValueForCharacteristicHandler = @conventi public typealias CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler = @convention(c) (UnsafeRawPointer) -> Void public typealias CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler = @convention(c) (UnsafeRawPointer, UnsafePointer, UnsafePointer, Int32, Int32) -> Void public typealias CB4UPeripheralDidReadRSSIHandler = @convention(c) (UnsafeRawPointer, Int32, Int32) -> Void +public typealias CB4UPeripheralDidUpdateNameHandler = @convention(c) (UnsafeRawPointer) -> Void @_cdecl("cb4u_peripheral_register_handlers") public func cb4u_peripheral_register_handlers( @@ -129,7 +130,8 @@ public func cb4u_peripheral_register_handlers( _ didWriteValueForCharacteristicHandler: @escaping CB4UPeripheralDidWriteValueForCharacteristicHandler, _ isReadyToSendWriteWithoutResponseHandler: @escaping CB4UPeripheralIsReadyToSendWriteWithoutResponseHandler, _ didUpdateNotificationStateForCharacteristicHandler: @escaping CB4UPeripheralDidUpdateNotificationStateForCharacteristicHandler, - _ didReadRSSIHandler: @escaping CB4UPeripheralDidReadRSSIHandler + _ didReadRSSIHandler: @escaping CB4UPeripheralDidReadRSSIHandler, + _ didUpdateNameHandler: @escaping CB4UPeripheralDidUpdateNameHandler ) { let instance = Unmanaged.fromOpaque(peripheralPtr).takeUnretainedValue() @@ -140,6 +142,7 @@ public func cb4u_peripheral_register_handlers( instance.isReadyToSendWriteWithoutResponseHandler = isReadyToSendWriteWithoutResponseHandler instance.didUpdateNotificationStateForCharacteristicHandler = didUpdateNotificationStateForCharacteristicHandler instance.didReadRSSIHandler = didReadRSSIHandler + instance.didUpdateNameHandler = didUpdateNameHandler } @_cdecl("cb4u_peripheral_identifier")