Objective Sharpie を使用して、NearbyMessages cocoapod の libGNSMessages.a バイナリとヘッダーから、Google の Nearby Messages API用の半機能 iOS C# バインディングを生成しました。そのバインド ライブラリを Xamarin.iOS プロジェクトに追加すると、GMSMessage オブジェクトと GMSMessageManager オブジェクトを作成してアクセスできるようになります。ただし、GMSMessageManager.publishWithMessage() を使用しようとすると、正しい引数の型を使用しているにもかかわらず、次の例外が発生します。
Foundation.MonoTouchException: Objective-C exception thrown.
Name: NSInvalidArgumentException
Reason: NSConcreteMutableAttributedString initWithString:: nil value
AppDelegate.cs の FinishedLaunching メソッド内から使用しているテスト コードを次に示します (チェックしたところ、マネージャーとメッセージは両方ともその型の有効なインスタンスです)。
GNSMessageManager manager = new GNSMessageManager(apiKey);
GNSMessage message = GNSMessage.MessageWithContent(NSData.FromString("Hello"));
GNSPublication pub = manager.PublicationWithMessage(message);
参照している Visual Studio バインディング プロジェクトの ApiDefinitions.cs からのバインディングを次に示します (コメントは、元の Objective-C ヘッダー ファイルのメソッド シグネチャです)。
// -(id<GNSPublication>)publicationWithMessage:(GNSMessage *)message;
[Export ("publicationWithMessage:")]
GNSPublication PublicationWithMessage (GNSMessage message);
そして、例外が発生している GNSMessageManager.g.cs (そのビジュアルスタジオプロジェクトによって生成された) のコードは次のとおりです。
public virtual GNSPublication PublicationWithMessage (GNSMessage message)
{ ...
if (IsDirectBinding) {
return Runtime.GetNSObject<GNSPublication> (global::ApiDefinitions.Messaging.IntPtr_objc_msgSend_IntPtr (this.Handle, Selector.GetHandle ("publicationWithMessage:"), message.Handle));
}
... }
デバッグ モードでは、これらの 3 つの引数すべてが少なくとも非 null であることが示されます。
これは同じ例外です: 'NSConcreteMutableAttributedString initWithString:: nil value' when using Google Nearby Messages . ただし、そのバグは修正されたとされており、Sharpie バインディングの基礎として使用した最新の CocoaPods は、XCode でテスト用の迅速なプロジェクトをビルドすると問題なく動作するため、おそらく私のバインディングが原因です。NearbyMonkeyに含まれている古いバイナリ C# NearbyMessages ライブラリも使用してみましたが、現在の iOS バージョンではクラッシュします。
ここまで読んでいただきありがとうございます。あなたが提供できる助けや提案は、非常に高く評価されます。