OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
104 stars 50 forks source link

NullReferenceException on opening notification on Xamarin.Android 4.0.0-beta1 #263

Closed skir closed 2 years ago

skir commented 2 years ago

Description

I am sending a simple notification from OneSignal portal. This notification consists of only title and message, no images, icons, buttons and other additional data.

When the notification is delivered to a device, I open it and get the NullReferenceException in Com.OneSignal.NativeConversion.NotificationToXam method.

I opened NativeConversion.cs file, and realized that there is no null check for notification.AdditionalData, notification.GroupedNotifications, notification.ActionButtons, and also notification.GetBackgroundImageLayout()

Environment

  1. Xamarin.Android
  2. Com.OneSignal 4.0.0-beta1 from Nuget

Steps to Reproduce Issue:

  1. Add version 4.0.0-beta1 of the Xamarin SDK to your project
  2. Initialize the SDK with your App ID
  3. Attempt to receive a simple push notification with only title and message
  4. Observe NullReferenceException inside OneSignal library

Stacktrace

  at Com.OneSignal.NativeConversion.NotificationToXam (Com.OneSignal.Android.OSNotification notification) [0x001b7] in /Users/tanay/Desktop/Xamarin_SDK/OneSignal_Xamarin-4_0_0/OneSignal-Xamarin-SDK/Com.OneSignal.Android/Utilities/NativeConversion.cs:11 
  at Com.OneSignal.NativeConversion.NotificationOpenedResultToXam (Com.OneSignal.Android.OSNotificationOpenedResult result) [0x00000] in /Users/tanay/Desktop/Xamarin_SDK/OneSignal_Xamarin-4_0_0/OneSignal-Xamarin-SDK/Com.OneSignal.Android/Utilities/NativeConversion.cs:71 
  at Com.OneSignal.OneSignalImplementation+OSNotificationOpenedHandler.NotificationOpened (Com.OneSignal.Android.OSNotificationOpenedResult notificationOpenedResult) [0x00000] in /Users/tanay/Desktop/Xamarin_SDK/OneSignal_Xamarin-4_0_0/OneSignal-Xamarin-SDK/Com.OneSignal.Android/OneSignalCallbacks.cs:106 
  at Com.OneSignal.Android.OneSignal+IOSNotificationOpenedHandlerInvoker.n_NotificationOpened_Lcom_onesignal_OSNotificationOpenedResult_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_p0) [0x00011] in /Users/tanay/Desktop/Xamarin_SDK/OneSignal_Xamarin-4_0_0/OneSignal-Xamarin-SDK/OneSignal.Android.Binding/obj/Release/generated/src/Com.OneSignal.Android.OneSignal.cs:1334 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.9(intptr,intptr,intptr)
Im-PJ commented 2 years ago

@jkasten2 @tanaynigam please merge the PR to fix this issue.

tanaynigam commented 2 years ago

Hey, thanks for reporting the issue and for the PR. We addressed it in the OneSignal-Xamarin-4.0.0-beta2 release which is live now.