简体   繁体   English

为什么在我调用发布/订阅方法时,我的NeighborsMessages Objective-C与C#绑定会引发NSInvalidArgumentException?

[英]Why does my NearbyMessages Objective-C to C# binding throw an NSInvalidArgumentException when I call publish/subscribe methods?

I've used Objective Sharpie to generate a semi-functional iOS C# binding for Google's Nearby Messages API from the libGNSMessages.a binary and headers in the NearbyMessages cocoapod. 我已经使用Objective Sharpie从libGNSMessages.neighborsMessages cocoapod中的二进制文件和标头为Google的 Neighbours Messages API生成了半功能iOS C#绑定。 Adding that binding library to a Xamarin.iOS project, I can create and access GMSMessage and GMSMessageManager objects. 将绑定库添加到Xamarin.iOS项目中,我可以创建和访问GMSMessage和GMSMessageManager对象。 When I try to use GMSMessageManager.publishWithMessage(), though, I get this exception, even though I'm using the correct argument type: 但是,当我尝试使用GMSMessageManager.publishWithMessage()时,即使使用了正确的参数类型,也会出现此异常:

Foundation.MonoTouchException: Objective-C exception thrown.  
Name: NSInvalidArgumentException 
Reason: NSConcreteMutableAttributedString initWithString:: nil value

Here's the test code I'm using from within the FinishedLaunching method in AppDelegate.cs (I checked, manager and message are both valid instances of their type): 这是我在AppDelegate.cs的FinishedLaunching方法中使用的测试代码(我检查过,manager和message都是其类型的有效实例):

  GNSMessageManager manager = new GNSMessageManager(apiKey);
  GNSMessage message = GNSMessage.MessageWithContent(NSData.FromString("Hello"));
  GNSPublication pub = manager.PublicationWithMessage(message);

Here's the binding from ApiDefinitions.cs in the Visual Studio binding project it's referring to (the comment is the method signature from the original objective-c header file): 这是它所引用的Visual Studio绑定项目中ApiDefinitions.cs的绑定(注释是原始Objective-C头文件中的方法签名):

    // -(id<GNSPublication>)publicationWithMessage:(GNSMessage *)message;
    [Export ("publicationWithMessage:")]
    GNSPublication PublicationWithMessage (GNSMessage message);

And here's the code in GNSMessageManager.g.cs (generated by that visual studio project) where the exception is being raised: 这是GNSMessageManager.g.cs(由该Visual Studio项目生成)中的代码,其中引发了异常:

    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));
        }
    ... }

Debug mode shows all three of those arguments are at least non-null. 调试模式显示所有这三个参数至少为非空。

It's the same exception here: 'NSConcreteMutableAttributedString initWithString:: nil value' when using Google Nearby Messages . 使用Google附近消息时,这里是相同的例外: 'NSConcreteMutableAttributedString initWithString :: nil value' However, that bug is allegedly fixed, and the up-to-date CocoaPods I used as the basis for the Sharpie binding work just fine when I build a test swift project in XCode, so my binding is probably the culprit. 但是,据称该错误已修复,当我在XCode中构建测试Swift项目时,我用作Sharpie绑定基础的最新CocoaPods效果很好,因此绑定可能是罪魁祸首。 There's also an older binary C# NearbyMessages library included in NearbyMonkey that I've tried using, but it crashes with current iOS versions. 我尝试使用的NearestMonkey中还包含一个较旧的二进制C#NearestMessages库,但该库在当前的iOS版本中崩溃了。

Thank you for taking the time to read this far. 感谢您抽出宝贵的时间阅读本文。 Any help or suggestions you could offer would be desperately appreciated. 您所能提供的任何帮助或建议将不胜感激。

OK, months later I finally figured out what was wrong. 好的,几个月后,我终于弄清楚出了什么问题。

The Google Nearby pod was distributed with a Resources folder - xcassets, some localization stuff, all display-related -- that I did not include in my binding project. Google附近的pod分发了一个Resources文件夹-xcassets,一些本地化的东西,所有与显示相关的东西-我没有包含在绑定项目中。 The error was triggered when Nearby tried to access those images, et cetera, to display a permissions prompt. 当附近尝试访问这些图像等以显示权限提示时,触发了错误。 Copying those resources to my Xamarin.iOS project fixed the error. 将这些资源复制到我的Xamarin.iOS项目中可修复该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 objective-c 调用中的 NSInvalidArgumentException - NSInvalidArgumentException in objective-c call 为什么React Native / Objective-C抱怨我用错误数量的参数调用我的方法? - Why does React Native/Objective-C complain that I call my method with the wrong number of arguments? Objective-C何时调用cellForRowAtIndexPath? - When does objective-C call the cellForRowAtIndexPath? 如何从JavaScript调用Objective-C方法? - How can I call Objective-C methods from JavaScript? Objective-c:UIColor * exception&#39;NSInvalidArgumentException? - Objective-c : UIColor * exception 'NSInvalidArgumentException? 快速调用Objective-C方法时崩溃 - Crashed when I call objective-c method in swift 当我尝试从另一个视图控制器(Objective-c?)访问变量时,为什么变量为null? - Why is my variable null when I am attempting to access it from another view controller (Objective-c? Objective-C中的绑定指针 - Binding pointers in Objective-C 方法队列Objective-c - Queue of methods Objective-c Objective-C:为什么偶尔打开我的应用程序时,我的应用程序不执行任何动画并做一些奇怪的意外事情? - Objective-C: Why does my app not perform any animations and do wonky unexpected things when I open up my app occasionally?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM