Skip to content

add CBCentralInitOptions#54

Merged
teach310 merged 6 commits intofeature/central_manager_init_optionsfrom
feature/options
Oct 26, 2023
Merged

add CBCentralInitOptions#54
teach310 merged 6 commits intofeature/central_manager_init_optionsfrom
feature/options

Conversation

@teach310
Copy link
Copy Markdown
Owner

@teach310 teach310 commented Oct 26, 2023

Description

CentralManagerを作る時に、BluetoothがOFFだったらONにするポップアップを出すオプションを追加

クラス名

https://learn.microsoft.com/en-us/dotnet/api/corebluetooth.cbcentralinitoptions?view=xamarin-ios-sdk-12
xamarinのをそのまま踏襲

キー名について

「kCBInitOptionShowPowerAlert」という値はswift側のprintで出力したもの。

https://developer.apple.com/documentation/corebluetooth/cbcentralmanageroptionshowpoweralertkey

appleのドキュメントでは定数の中身については書かれていないため、この定数を取得するNativeMethodsを定義するのが無難ではあると思う。
xamarinではおそらく定数を取ってきている。

https://github.com/xamarin/xamarin-macios/blob/a0eec0c265eeb3ad5b3e01e08793e326d890a647/src/corebluetooth.cs#L33

が、定数取ってくるためにNativeMethods書いたりするのが手間だったため一番楽で処理速度も当然最速なcsharp側に直書きという方法に一旦している。

ToNativeDictionaryについて

xamarinではDictionaryContainerを継承して、オプションをセットすると同時にNativeのDictionaryを更新しているようだった。
https://learn.microsoft.com/en-us/dotnet/api/foundation.dictionarycontainer?view=xamarin-ios-sdk-12

でもこれだと options が持ってるNSMutableDictionaryのDisposeが手間。
xamarinだとやっていないっぽかった。

そのため使う時にだけ作って使い捨てるという実装にしている。

NativeMethodsの引数なぜIntPtrなのか

SafeHandleはクラスだが、nullを渡したらエラーがでた。
SafeHandleをnullとして渡すドキュメントが見つからなかったためIntPtrを引数にとるようにした。

また、別の箇所でもSafeHandleにnullはいれないようにしている

Test

実機で動くことを確認。

teach310 added 6 commits October 26, 2023 15:59
## クラス名
https://learn.microsoft.com/en-us/dotnet/api/corebluetooth.cbcentralinitoptions?view=xamarin-ios-sdk-12
xamarinのをそのまま踏襲

## キー名について
「kCBInitOptionShowPowerAlert」という値はswift側のprintで出力したもの。

https://developer.apple.com/documentation/corebluetooth/cbcentralmanageroptionshowpoweralertkey

appleのドキュメントでは定数の中身については書かれていないため、この定数を取得するNativeMethodsを定義するのが無難ではあると思う。
xamarinではおそらく定数を取ってきている。

https://github.com/xamarin/xamarin-macios/blob/a0eec0c265eeb3ad5b3e01e08793e326d890a647/src/corebluetooth.cs#L33

が、定数取ってくるためにNativeMethods書いたりするのが手間だったため一番楽で処理速度も当然最速なcsharp側に直書きという方法に一旦している。

## ToNativeDictionaryについて
xamarinではDictionaryContainerを継承して、オプションをセットすると同時にNativeのDictionaryを更新しているようだった。
https://learn.microsoft.com/en-us/dotnet/api/foundation.dictionarycontainer?view=xamarin-ios-sdk-12

でもこれだと options が持ってるNSMutableDictionaryのDisposeが手間。
xamarinだとやっていないっぽかった。

そのため使う時にだけ作って使い捨てるという実装にしている。
## なぜIntPtrなのか
SafeHandleはクラスだが、nullを渡したらエラーがでた。
SafeHandleをnullとして渡すドキュメントが見つからなかったためIntPtrを引数にとるようにした。

また、別の箇所でもSafeHandleにnullはいれないようにしている
@teach310 teach310 added the add label Oct 26, 2023
@teach310 teach310 changed the base branch from develop to feature/central_manager_init_options October 26, 2023 12:57
@teach310 teach310 changed the title Feature/options add CBCentralInitOptions Oct 26, 2023
@teach310 teach310 merged commit d84a533 into feature/central_manager_init_options Oct 26, 2023
@teach310 teach310 deleted the feature/options branch October 26, 2023 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant