TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
211 stars 49 forks source link

Need testing with iOS simulator #107

Closed binhtt6 closed 10 months ago

binhtt6 commented 1 year ago

Hello, is there any one try this library with iOS simulator? I tested with Android using MAUI blazor and everything is fine. But no luck with iOS simulator and device. Thanks

TobiasBuchholz commented 1 year ago

I have developed the library using an iOS simulator, so it should basically work. I haven't tried it with an MAUI blazor app yet, but I don't know a reason why it shouldn't work as well. What kind of problem do you have?

binhtt6 commented 1 year ago

image Hi, i put this, and it worked in android but in ios, i can not get firebase id although GoogleService-Info.plist is added

vIceBerg commented 1 year ago

I just discovered that when you put the code in the OnApprearing, it works on Android but we get an exception on iOS.

The code fails when we call GetTokenAsync(). If we put teh exact same code in an handler (ie: button click), it works.

The code was in the AppShell OnAppearing overriden method. Maybe this code get called before some initialization occures in the iOS implementation.

I'll try to find a work-around later today, hoping that @TobiasBuchholz will see this message and give us some infos

System.NullReferenceException

at Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.GetTokenAsync() at TuxedoMobileApp.AppShell.OnAppearing() in /Users/vincent/dev/Tuxedo/TuxedoMobileApp/AppShell.xaml.cs:line 73 at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state) at Foundation.NSAsyncSynchronizationContextDispatcher.Apply() at Foundation.NSAttributedString..ctor(NSData data, NSDictionary options, NSDictionary& resultDocumentAttributes, NSError& error) at Foundation.NSAttributedString..ctor(NSData data, NSAttributedStringDocumentAttributes options, NSDictionary& resultDocumentAttributes, NSError& error) at Foundation.NSAttributedString..ctor(NSData data, NSAttributedStringDocumentAttributes documentAttributes, NSError& error) at Microsoft.Maui.Platform.LabelExtensions.UpdateTextHtml(UILabel platformLabel, ILabel label) at Microsoft.Maui.Controls.Platform.LabelExtensions.UpdateText(UILabel platformLabel, Label label) at Microsoft.Maui.Controls.Label.MapText(ILabelHandler handler, Label label) at Microsoft.Maui.Controls.Label.MapTextType(LabelHandler handler, Label label) at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.Controls.Label, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.LabelHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILabel, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.MauiLabel, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILabel, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.MauiLabel, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.ScrollViewHandler.UpdateContentView(IScrollView scrollView, IScrollViewHandler handler) at Microsoft.Maui.Handlers.ScrollViewHandler.MapContent(IScrollViewHandler handler, IScrollView scrollView) at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IScrollView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IScrollViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IScrollView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIScrollView, Microsoft.iOS, Version=16.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IScrollView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIScrollView, Microsoft.iOS, Version=16.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler) at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page) at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ViewExtensions.ToHandler(IView view, IMauiContext context) at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.SetPageRenderer(Page page, ShellContent shellContent) at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.LoadRenderers() at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.ViewDidLoad() at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) at TuxedoMobileApp.Program.Main(String[] args) in /Users/vincent/dev/Tuxedo/TuxedoMobileApp/Platforms/iOS/Program.cs:line 13

vIceBerg commented 1 year ago

Here's another detail. The AppShell.OnAppearing method gets called before the iOS.FinishedLaunching event is triggered. That's why I think we get an exception.

So the code in MauiProgram:

events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) => { CrossFirebase.Initialize(app, launchOptions, CreateCrossFirebaseSettings()); return false; }));

Is called after we use the service in the OnAppearing method

binhtt6 commented 1 year ago

HI, it will try again and tell you the result. thanks

kirakosyan commented 1 year ago

hi I have similar issue. All is great with Android. When testing with iOS real device getting this

{System.NullReferenceException: Object reference not set to an instance of an object. at Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.GetTokenAsync() at MobileAppX.App.OnStart() in }

It is called from App.xaml.cs in MAUI app I tried to debug to check if MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)

is called first, yes it is. So it is initialized at the moment when it throws null exception

tranb3r commented 1 year ago

I'm using WillFinishLaunching instead of FinishedLaunching and I do not have this kind of issue. Maybe you should try it.

kirakosyan commented 1 year ago

Yes, thanks, that helped. Would like to understand the difference 👯