urbanairship/urbanairship-xamarin

Method AddCustomEvent crash on iOS

Closed this issue · 2 comments

Preliminary Info

What Airship dependencies are you using?

  • airship.netstandard (16.0.1)
  • airship.ios (16.5.1)

What are the versions of any relevant development tools you are using?

  • JetBrains Rider (2022.1)
  • Visual Studio for Mac (8.10.22 - build 11)

Report

What unexpected behavior are you seeing?

In iOS, the call to the method AddCustomEvent crash with this exception
SIGABRT: [<__NSDictionary0 0x7fff805f8120> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Nom. In Android, the method AddCustomEvent works as exepected.

What is the expected behavior?

No crash when call method AddCustomEvent

What are the steps to reproduce the unexpected behavior?

Using netstandard api, the following code crash on iOS :

readonly IAirship _airship;

public void TagEvent(string eventName, IDictionary<string, string> attributes = null) {
            var customEvent = new CustomEvent {
                EventName = eventName,
                EventValue = 0d,
            };
            if (attributes != null) {
                foreach (var attribute in attributes) {
                    customEvent.AddProperty(attribute.Key, attribute.Value);
                }
            }
            _airship.AddCustomEvent(customEvent);
        }

Using iOS classes, the following code also crashes

			var customEvent = UACustomEvent.Event("Test", (string)null);
			var key = new NSString("My property");
			customEvent.Properties.SetValueForKey(new NSString("A value"), key);
			UAirship.Analytics.AddEvent(customEvent);

And the following code works doesn't crash

var customEvent = UACustomEvent.Event("Test", (string)null);
 var properties = new NSMutableDictionary<NSString, NSObject>();
 var key = new NSString("My property");
 properties.SetValueForKey(new NSString("A value"), key);
 customEvent.Properties = new NSDictionary<NSString, NSObject>(properties.Keys, properties.Values);
 UAirship.Analytics.AddEvent(customEvent);

Thanks for the report, we will get this fixed in the next release.

This crash should be fixed with the version 16.1.0
I will close the ticket, feel free to reopen it if needed