diff --git a/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Peripheral.cs b/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Peripheral.cs index c1454e5..2b64289 100644 --- a/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Peripheral.cs +++ b/Assets/CoreBluetooth/Samples/12_Debug/SampleDebug_Peripheral.cs @@ -20,7 +20,8 @@ public class SampleDebug_Peripheral : MonoBehaviour, ICBPeripheralManagerDelegat void Start() { - _peripheralManager = new CBPeripheralManager(this); + var initOptions = new CBPeripheralManagerInitOptions() { ShowPowerAlert = true }; + _peripheralManager = new CBPeripheralManager(this, initOptions); _disposables.Add(_peripheralManager); } 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 23d426d..09dccd7 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 082fb10..48e8a9d 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/CBPeripheralManager.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManager.cs index cfe7269..4084297 100644 --- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManager.cs +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManager.cs @@ -54,9 +54,17 @@ public ICBPeripheralManagerDelegate Delegate static readonly int s_maxATTRequests = 10; Queue _attRequestDisposables = new Queue(); - public CBPeripheralManager(ICBPeripheralManagerDelegate peripheralDelegate = null) + public CBPeripheralManager(ICBPeripheralManagerDelegate peripheralDelegate = null, CBPeripheralManagerInitOptions options = null) { - _handle = SafeNativePeripheralManagerHandle.Create(); + if (options == null) + { + _handle = SafeNativePeripheralManagerHandle.Create(); + } + else + { + using var optionsDict = options.ToNativeDictionary(); + _handle = SafeNativePeripheralManagerHandle.Create(optionsDict.Handle); + } Delegate = peripheralDelegate; _nativePeripheralManagerProxy = new NativePeripheralManagerProxy(_handle, this); CallbackContext = SynchronizationContext.Current; diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManagerInitOptions.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManagerInitOptions.cs new file mode 100644 index 0000000..d0d3b86 --- /dev/null +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManagerInitOptions.cs @@ -0,0 +1,25 @@ +using CoreBluetooth.Foundation; + +namespace CoreBluetooth +{ + public class CBPeripheralManagerInitOptions + { + public static readonly string ShowPowerAlertKey = "kCBInitOptionShowPowerAlert"; + public bool? ShowPowerAlert { get; set; } = null; + + public CBPeripheralManagerInitOptions() + { + } + + internal NSMutableDictionary ToNativeDictionary() + { + var dict = new NSMutableDictionary(); + if (ShowPowerAlert.HasValue) + { + using var value = new NSNumber(ShowPowerAlert.Value); + dict.SetValue(ShowPowerAlertKey, value.Handle); + } + return dict; + } + } +} diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManagerInitOptions.cs.meta b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManagerInitOptions.cs.meta new file mode 100644 index 0000000..1a73590 --- /dev/null +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/CBPeripheralManagerInitOptions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96855c9f44d5744e6b6eeefaa3cc4385 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: 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 57064fd..76f8178 100644 --- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/NativeMethods.cs @@ -177,7 +177,7 @@ internal static extern int cb4u_peripheral_characteristic_properties( ); [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)] - internal static extern SafeNativePeripheralManagerHandle cb4u_peripheral_manager_new(); + internal static extern SafeNativePeripheralManagerHandle cb4u_peripheral_manager_new(IntPtr options); [DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)] internal static extern void cb4u_peripheral_manager_release(IntPtr handle); diff --git a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralManagerHandle.cs b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralManagerHandle.cs index 50e42cf..bc281ae 100644 --- a/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralManagerHandle.cs +++ b/Packages/com.teach310.core-bluetooth-for-unity/Runtime/SafeNativePeripheralManagerHandle.cs @@ -23,13 +23,23 @@ public class SafeNativePeripheralManagerHandle : SafeHandleZeroOrMinusOneIsInval SafeNativePeripheralManagerHandle() : base(true) { } - internal static SafeNativePeripheralManagerHandle Create() + internal static SafeNativePeripheralManagerHandle Create(IntPtr options) { - var instance = NativeMethods.cb4u_peripheral_manager_new(); + var instance = NativeMethods.cb4u_peripheral_manager_new(options); instance.RegisterHandlers(); return instance; } + internal static SafeNativePeripheralManagerHandle Create(Foundation.SafeNSMutableDictionaryHandle options) + { + return Create(options.DangerousGetHandle()); + } + + internal static SafeNativePeripheralManagerHandle Create() + { + return Create(IntPtr.Zero); + } + void RegisterHandlers() { NativeMethods.cb4u_peripheral_manager_register_handlers( diff --git a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheralManager.swift b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheralManager.swift index c737318..7e6f917 100644 --- a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheralManager.swift +++ b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CB4UPeripheralManager.swift @@ -13,10 +13,10 @@ public class CB4UPeripheralManager : NSObject { public var didReceiveReadRequestHandler: CB4UPeripheralManagerDidReceiveReadRequestHandler? public var didReceiveWriteRequestsHandler: CB4UPeripheralManagerDidReceiveWriteRequestsHandler? - public override init() { + public init(_ options: [String: Any]? = nil) { super.init() - peripheralManager = CBPeripheralManager(delegate: self, queue: nil) + peripheralManager = CBPeripheralManager(delegate: self, queue: nil, options: options) } func selfPointer() -> UnsafeMutableRawPointer { diff --git a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift index f1cf260..94d30a6 100644 --- a/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift +++ b/Plugins/CoreBluetoothForUnity/Sources/CoreBluetoothForUnity/CoreBluetoothForUnity.swift @@ -322,8 +322,14 @@ public func cb4u_peripheral_characteristic_properties( } @_cdecl("cb4u_peripheral_manager_new") -public func cb4u_peripheral_manager_new() -> UnsafeMutableRawPointer { - return Unmanaged.passRetained(CB4UPeripheralManager()).toOpaque() +public func cb4u_peripheral_manager_new(_ optionsPtr: UnsafeRawPointer?) -> UnsafeMutableRawPointer { + var options: [String: Any]? = nil + if let optionsPtr = optionsPtr { + let nsMutableDictionary = Unmanaged.fromOpaque(optionsPtr).takeUnretainedValue() + options = nsMutableDictionary as? [String: Any] + } + + return Unmanaged.passRetained(CB4UPeripheralManager(options)).toOpaque() } @_cdecl("cb4u_peripheral_manager_release")