简体   繁体   中英

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. Adding that binding library to a Xamarin.iOS project, I can create and access GMSMessage and GMSMessageManager objects. When I try to use GMSMessageManager.publishWithMessage(), though, I get this exception, even though I'm using the correct argument type:

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):

  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):

    // -(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:

    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 . 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. There's also an older binary C# NearbyMessages library included in NearbyMonkey that I've tried using, but it crashes with current iOS versions.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM