Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Xamarin iOS Push Notification with FCM throwing Exception #9960


User avatar
0
Jorahealth created
  • What is your product version? 9.2.0
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .NET CORE

Could we please get help with the following:

We are trying to integrate FCM pushnotification in Xamarin.forms app. It's works sucessfully in our ASP.NET ZERO Android project and sample iOS project but ** not with our ASP.NET ZERO iOS project. In the case of iOS, we are getting an exception, and not able to send notification. Could you please help us resolve this?

In the process we are able to generate the FCM token, but app is crashing when 'Allow pushnotification request permission' popup appears on device.
In "WebRequestExecuter.cs" class it handle the exception in "HandleDefaultException" method. The Exception is =>" An object reference is required for the non-static field, method, or property 'Decisively.Core.Threading.WebRequestExecuter.exception'." And Exception throws from Main.cs class file

Exception Log

at (wrapper managed-to-native) System.Threading.Thread.Abort_internal(System.Threading.InternalThread,object) at System.Threading.Thread.Abort () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Threading/Thread.cs:448 at Decisively.AppDelegate+<>c.<SetExitAction>b__3_0 () [0x00001] in /Users/aswanipu/Jora/aspnet-core/src/Decisively.Mobile.iOS/AppDelegate.cs:89 at Decisively.ViewModels.Base.UserConfigurationManager+<>c.<GetAsync>b__4_2 (System.Exception _) [0x00001] in /Users/aswanipu/Jora/aspnet-core/src/Decisively.Mobile.Shared/ViewModels/Base/UserConfigurationManager.cs:60 at Decisively.Core.Threading.WebRequestExecuter.HandleDefaultException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00140] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00300] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.Execute[TResult] (System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback, System.Action finallyCallback) [0x00410] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleDefaultException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00117] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00300] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.Execute[TResult] (System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback, System.Action finallyCallback) [0x00410] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleDefaultException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00117] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00300] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.Execute[TResult] (System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback, System.Action finallyCallback) [0x00410] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleDefaultException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00117] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00300] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.Execute[TResult] (System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback, System.Action finallyCallback) [0x00410] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleDefaultException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00117] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.HandleException[TResult] (System.Exception exception, System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback) [0x00300] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.Core.Threading.WebRequestExecuter.Execute[TResult] (System.Func1[TResult] func, System.Func2[T,TResult] successCallback, System.Func2[T,TResult] failCallback, System.Action finallyCallback) [0x00410] in <5fd16953003141bbb0bdead1209c5472>:0 at Decisively.ViewModels.Base.UserConfigurationManager.GetAsync (System.Func1[TResult] successCallback) [0x000da] in /Users/aswanipu/Jora/aspnet-core/src/Decisively.Mobile.Shared/ViewModels/Base/UserConfigurationManager.cs:40 at Decisively.ViewModels.Base.UserConfigurationManager.GetIfNeedsAsync () [0x00034] in /Users/aswanipu/Jora/aspnet-core/src/Decisively.Mobile.Shared/ViewModels/Base/UserConfigurationManager.cs:31 at Decisively.App.OnStart () [0x00051] in /Users/aswanipu/Jora/aspnet-core/src/Decisively.Mobile.Shared/App.xaml.cs:53 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.4.1.3/src/Xamarin.iOS/Foundation/NSAction.cs:178 at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.4.1.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.fraframework/Versions/14.4.1.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at Decisively.Application.Main (System.String[] args) [0x00002] in /Users/aswanipu/Jora/aspnet-core/src/Decisively.Mobile.iOS/Main.cs:15

The process we followed to integrate the iOS app to FCM is as follows: Using Apple Developer account, we created an Id, with this iOS project bundle id we enabled pushnotification. We also created Provisional certificate and and installed in xcode. We are registerd our ASP.NET ZERO Xamarin iOS app in Firebase using bundle id and uploaded AuthKey certificate. From the app side, we enabled RemoteNotification and Background mode in info.plist file and also enabled Pushnotification in Entitlement.plist file. We added GoogleService-info.plist file to project and set the build action as BundleResource.

To check code, I have attached these to a share folderhere (please see attached AppDelegate.cs class file and UserNotificationCenterDelegate.cs file.)

Your help is much appreciated.

Many thanks in advance


5 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    don't use WebRequestExecuter in AppDelegate.cs and use it as is.

  • User Avatar
    0
    Jorahealth created

    Thank you @alper

    We are tried with commenting the the codes which use WebRequestExecuter directly in AppDelegate.cs class.** But it did not work. ** On Further investigation we understand that When we work with FCM, the code in AppDelegate.cs class "ApplicationBootstrapper.InitializeIfNeeds<DecisivelyXamarinIosModule>();" calling the method "userConfigurationService.GetAsync(AccessTokenManager.IsUserLoggedIn)". And retuns null as result in Decisively.ViewModels.Base.UserConfigurationManager.cs class. And it throwing null object reference exception and calling App.ExitApplication(); method.

    Without FCM integration code it works perfectly and got result.

  • User Avatar
    0
    alper created
    Support Team

    In AppDelegate.cs class there's no call to UserConfigurationManager.GetAsync()

    this code

     ApplicationBootstrapper.InitializeIfNeeds<AbpZeroTemplateXamarinIosModule>();
    

    runs the below

    
     if (IsInitialized)
                {
                    return;
                }
    
                AbpBootstrapper = AbpBootstrapper.Create<T>(options =>
                {
                    //Interceptors (dynamic proxying) are not supported in IOS platform. Also, it's not needed on the client side.
                    options.DisableAllInterceptors = true;
                });
    
                AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(f =>
                {
                    f.LogUsing<TraceLoggerFactory>();
                });
    
                AbpBootstrapper.Initialize();
    
  • User Avatar
    0
    Jorahealth created

    Yes you are right, there is no call to UserConfigurationManager.GetAsync() in AppDelegate.cs. On the further investigation we found that UserConfigurationManager.GetAsync() method is calling from App.Xamal.cs file. And it returns reult as null.

    So to solve this issue, we did some code modifications in AppDelegate.cs

    1. Removed delay from RegisterForRemoteNotifications() method
    2. Added a 30 seconds delay before calling return base.FinishedLaunching(app, options); in FinishedLaunching() method.

    The app then works perfectly and got expected result for UserConfigurationManager.GetAsync() method. Also received FCM test notification too.

    **Is this the best way to solve this? **

  • User Avatar
    0
    alper created
    Support Team

    this is a solution but if there's a callback method RegisterForRemoteNotifications() method, you can call FinishLaunching in there. Otherwise 3 sec maybe issue when using slow networks.