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

iOS crashed when call OneSignal.Current.IdsAvailableAsync() when user don't allow notification #240

Closed kritsadadechawantana closed 2 years ago

kritsadadechawantana commented 2 years ago

Description: iOS crashed when call OneSignal.Current.IdsAvailableAsync() when user don't allow notification

Environment

  1. Xamarin.Forms 4.8.0.1687
  2. Com.OneSignal 3.10.4
  3. iPhone xs max
  4. iOS 14.7.1

Steps to Reproduce Issue:

  1. Add nuget Com.OneSignal 3.10.4 to your shared project in xamarin forms project
  2. Initialize the SDK with your App ID follow onesignal document
  3. Use the code below any place you want to get ids available
    try
    {
      var idsAvailable = await OneSignal.Current.IdsAvailableAsync();
    }
    catch (Exception ex)
    {
    // do anything
    }
  4. Build and run on real device
  5. At the first time to run app. OS propmt os notification permission dialog
  6. Select "don't allow" on notification permission dialog
  7. First time app run normally can get "idsAvailable" data and no any exception
  8. Kill app and run again
  9. The second time to run. Can get "idsAvailable" data but app is crashed!
  10. Can't capture and ignore exception with "try catch" code

Anything else: ExceptionMessage

TaskCompletionSource`1[TResult].SetResult (TResult result)
OneSignalExtensions+<>c__DisplayClass1_0.<IdsAvailableAsync>b__0 (System.String playerId, System.String pushToken)
OneSignalImplementation+<>c__DisplayClass14_0.<IdsAvailable>b__0 (System.String playerId, System.String pushToken)
Trampolines+SDOSIdsAvailableBlock.Invoke (System.IntPtr block, System.IntPtr arg0, System.IntPtr arg1)
(wrapper native-to-managed) ObjCRuntime.Trampolines+SDOSIdsAvailableBlock.Invoke(intptr,intptr,intptr)
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)

This exception breakpoint at

    UIApplication.Main(args, null, "AppDelegate");

in iOS project "Main.cs" file

tanaynigam commented 2 years ago

@kritsadadechawantana Thanks for reporting the issue. We have a release OneSignalSDK.Xamarin-4.0.0 in which this issue no longer seems to exist.

we have moved the push notification subscription status' ids to a new api. You check out our documentation on the changes regarding the status ids in our OneSignal Xamarin 4.0.0 API reference documentation

Please note that we have changed the package name and namespace for the SDK from Com.OneSignal to OneSignalSDK.Xamarin and would require you to remove the previous package name and add the new package name to import the SDK in your code.

Additionally, when searching for the package on nuget.org, you will be required to search for OneSignalSDK.Xamarin to import the package