add CBCentralInitOptions#54
Merged
teach310 merged 6 commits intofeature/central_manager_init_optionsfrom Oct 26, 2023
Merged
Conversation
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はいれないようにしている
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
実機で動くことを確認。