microsoft / appcenter-sdk-dotnet

Development repository for the App Center SDK for .NET platforms, including Xamarin
Other
309 stars 141 forks source link

Xamarin Forms (iOS only), Push.PushNotificationReceived event only fires for the first push notification received #757

Closed eliaspuurunen closed 5 years ago

eliaspuurunen commented 6 years ago

Description

Platform: iOS, Xamarin Forms (.NET Standard)

On Xamarin Forms (iOS only), the Push.PushNotificationReceived event only fires for the first push notification received. Subsequent push notifications, either when the app is in the foreground or background, do not fire the event even if the notification is tapped.

We have also tried disabling method swizzling (as per https://docs.microsoft.com/en-us/appcenter/sdk/push/xamarin-ios#disable-automatic-forwarding-of-application-delegates-methods-to-app-center-services) and noticed that DidReceiveRemoteNotification would not fire after 1st push received.

Enabling/disabling Background Notification in info.plist does not seem to have an effect.

Repro Steps

Please list the steps used to reproduce your issue.

  1. Subscribe to Push.PushNotificationReceived in AppDelegate.FinishedLaunching or in the Xamarin Forms app OnStart
  2. Send a push notification from the AppCenter web console to the app
  3. The event fires when the notification is tapped.
  4. Send a 2nd push notification via web console.
  5. The event does not fire when notification tapped, either in foreground or background.

Details

  1. What is your app platform (Xamarin.Android or Xamarin.iOS or UWP)?
    • Xamarin.Forms, iOS only (Events working as expected on UWP and Android)
  2. If using Xamarin.Forms or if using portable/shared code to call our SDK APIs, are you using shared project, PCL code or .NET standard code for the application? Which .NET standard version or which PCL profile?
    • .NET standard 2.0.
  3. Which SDK version are you using?
    • 1.8.0, upgraded to 1.9.0, same behavior
  4. Which OS version did you experience the issue on?
    • iOS 12.0 (16A366), Xamarin Forms 3.2.0.839982
  5. What device version did you see this error on? Were you using an emulator or a physical device?
    • iPad 9.7" (MR7G2CL/A)
  6. What third party libraries are you using?
    • Xam.Plugin.Connectivity, Xam.Plugin.Media, Xamarin.Essentials, ZXing.Net.Mobile.Forms
  7. Please enable verbose logging for your app using AppCenter.LogLevel = LogLevel.Verbose before your call to AppCenter.Start(...) and include the logs here:

Note: In this log, five push notifications were sent. The event fired twice as I had some breakpoints enabled. The remaining 3 did not trigger the event.


Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Mono.Security.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/.monotouch-64/Xamarin.iOS.dll [External]
Thread started:  #2
2018-10-02 09:00:35.138 Internal.Passport.iOS[2843:1011954] warning: Symbol file /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Toasts.Forms.Plugin.iOS.dll.mdb doesn't match image /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Toasts.Forms.Plugin.iOS.dll
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/OpenTK-1.0.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Xml.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Xamarin.Forms.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Net.Http.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.ServiceModel.Internals.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Runtime.Serialization.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Xamarin.Forms.Platform.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AppCenter.Push.iOS.Bindings.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AppCenter.Push.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Xamarin.Essentials.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/FFImageLoading.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/WebP.Touch.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/FFImageLoading.Platform.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/FFImageLoading.Forms.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/FFImageLoading.Forms.Platform.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Plugin.Permissions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Plugin.Media.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Reactive.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Splat.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/ReactiveUI.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/.monotouch-64/Microsoft.AppCenter.iOS.Bindings.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/ImageCircle.Forms.Plugin.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/BTProgressHUD.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Acr.UserDialogs.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/zxing.portable.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/ZXing.Net.Mobile.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/ZXing.Net.Mobile.Forms.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/ZXingNetMobile.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/ZXing.Net.Mobile.Forms.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Syncfusion.Licensing.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Syncfusion.SfChart.XForms.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Syncfusion.SfChart.XForms.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Numerics.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Data.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Xml.Linq.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Newtonsoft.Json.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Internal.Data.Portable.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Toasts.Forms.Plugin.Abstractions.dll
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/NdefLibrary.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Internal.Data.Portable.Tags.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Plugin.SecureStorage.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Plugin.Connectivity.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Markdig.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/SkiaSharp.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/SkiaSharp.Extended.Svg.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Xam.Forms.MarkdownView.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Poz1.NFCForms.Abstract.dll
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/XamU.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/XamU.Infrastructure.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Numerics.Vectors.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Buffers.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Runtime.CompilerServices.Unsafe.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Memory.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Threading.Tasks.Extensions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.IO.Pipelines.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/System.Threading.Channels.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.Extensions.Primitives.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.Http.Features.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.Connections.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.Extensions.Logging.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.Extensions.DependencyInjection.Abstractions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.Extensions.Options.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.Extensions.Logging.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.SignalR.Common.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.Extensions.DependencyInjection.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.SignalR.Protocols.Json.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.SignalR.Client.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Plugin.SecureStorage.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AppCenter.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Plugin.Connectivity.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.Http.Connections.Common.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.Http.Connections.Client.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Microsoft.AspNetCore.SignalR.Client.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Internal.Passport.dll
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Toasts.Forms.Plugin.iOS.dll
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/Internal.Passport.iOS.exe
2018-10-02 09:00:36.527 Internal.Passport.iOS[2843:1011954] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
Thread started: <Thread Pool> #3
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
Thread started: <Thread Pool> #6
Resolved pending breakpoint at 'App.xaml.cs:62,1' to void Internal.Passport.App.OnGotPush (object sender, Microsoft.AppCenter.Push.PushNotificationReceivedEventArgs e) [0x00000].
Resolved pending breakpoint at 'App.xaml.cs:93,1' to void Internal.Passport.App.HandlePushNotification (Microsoft.AppCenter.Push.PushNotificationReceivedEventArgs e, bool fromBackground) [0x00000].
Thread started:  #7
Loaded assembly: /private/var/containers/Bundle/Application/25017612-F4D1-4D24-A987-0D64E4640C97/Internal.Passport.iOS.app/HCI.Internal.dll [External]
2018-10-02 09:00:37.526 Internal.Passport.iOS[2843:1011954] [AppCenter] VERBOSE: +[MSAppDelegateForwarder addTraceBlock:]_block_invoke_2/113 Start buffering traces.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: +[MSAppDelegateForwarder load]_block_invoke/57 Application delegate forwarder is enabled. It may use swizzling.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: +[MSAppDelegateForwarder swizzleOriginalSelector:withCustomSelector:originalClass:]_block_invoke/272 Selector 'setDelegate:' of class 'UIApplication' is swizzled.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: +[MSAppDelegateForwarder swizzleOriginalSelector:withCustomSelector:originalClass:]_block_invoke/272 Selector 'application:didRegisterForRemoteNotificationsWithDeviceToken:' of class 'AppDelegate' is swizzled.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: +[MSAppDelegateForwarder swizzleOriginalSelector:withCustomSelector:originalClass:]_block_invoke/272 Selector 'application:didReceiveRemoteNotification:fetchCompletionHandler:' of class 'AppDelegate' is swizzled.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: +[MSAppDelegateForwarder swizzleOriginalSelector:withCustomSelector:originalClass:]_block_invo
ke/272 Selector 'application:didFailToRegisterForRemoteNotificationsWithError:' of class 'AppDelegate' is swizzled.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: +[MSAppDelegateForwarder swizzleOriginalSelector:withCustomSelector:originalClass:]_block_invoke/272 Selector 'application:didReceiveRemoteNotification:' of class 'AppDelegate' is swizzled.
2018-10-02 09:00:37.527 Internal.Passport.iOS[2843:1011954] [AppCenter] VERBOSE: +[MSAppDelegateForwarder flushTraceBuffer]/436 Stop buffering traces, flushed.
2018-10-02 09:00:37.530 Internal.Passport.iOS[2843:1011954] [AppCenter] DEBUG: -[MSSessionContext init]/40 67 session(s) in the history.
2018-10-02 09:00:37.533 Internal.Passport.iOS[2843:1011954] [AppCenter] VERBOSE: -[MSSessionContext setSessionId:]/71 Stored new session with id:(null) and timestamp: 2018-10-02 13:00:37 +0000.
2018-10-02 09:00:37.535 Internal.Passport.iOS[2843:1011954] [AppCenter] INFO: -[MSHttpIngestion networkStateChanged]/418 Internet connection is up.
2018-10-02 09:00:37.535 Internal.Passport.iOS[2843:1011954] [AppCenter] INFO: -[MSHttpIngestion networkStateChanged]/418 Internet connection is up.
2018-10-02 09:00:37.554 Internal.Passport.iOS[2843:1011954] [AppCenter] INFO: -[MSAppCenter configureWithAppSecret:transmissionTargetToken:fromApplication:]/274 App Center SDK configured successfully.
2018-10-02 09:00:37.554 Internal.Passport.iOS[2843:1011954] [AppCenter] VERBOSE: -[MSAppCenter start:withServices:fromApplication:]/298 Start services MSPush from an application
2018-10-02 09:00:37.555 Internal.Passport.iOS[2843:1011954] [AppCenterPush] VERBOSE: -[MSPush registerForRemoteNotifications]/220 Registering for push notifications
2018-10-02 09:00:37.555 Internal.Passport.iOS[2843:1011954] [AppCenterPush] INFO: -[MSPush applyEnabledState:]/197 Push service has been enabled.
2018-10-02 09:00:37.555 Internal.Passport.iOS[2843:1011954] [AppCenterPush] VERBOSE: -[MSPush startWithChannelGroup:appSecret:transmissionTargetToken:fromApplication:]/145 Started push service.
2018-10-02 09:00:37.563 Internal.Passport.iOS[2843:1011984] [AppCenterPush] VERBOSE: -[MSPush registerForRemoteNotifications]_block_invoke_2/254 Push notifications authorization was granted.
2018-10-02 09:00:37.563 Internal.Passport.iOS[2843:1011984] [AppCenter] DEBUG: -[MSChannelUnitDefault enqueueItem:]_block_invoke/195 Saving log, type: startService.Resolved pending breakpoint at 'Root.xaml.cs:136,1' to void Internal.Passport.Home.Root.OnGotToastRequest (Internal.Passport.IToaster sender, Internal.Passport.ToastDetails args) [0x00014].

Resolved pending breakpoint at 'Root.xaml.cs:105,1' to void Internal.Passport.Home.Root.OnGotPush (Internal.Passport.App sender, Internal.Passport.LocalPushNotificationRequest request) [0x00014].
Resolved pending breakpoint at 'RootViewModel.cs:107,1' to string Internal.Passport.Home.RootViewModel.get_CompaniesTitle () [0x00000].
Resolved pending breakpoint at 'RootViewModel.cs:108,1' to string Internal.Passport.Home.RootViewModel.get_AnnouncementsTitle () [0x00000].
Resolved pending breakpoint at 'LandingPage.xaml.cs:42,1' to void Internal.Passport.Home.LandingPage.OnEntryTapped (object sender, System.EventArgs e) [0x00012].
Thread started: <Thread Pool> #8
2018-10-02 09:00:38.379 Internal.Passport.iOS[2843:1011954] [AppCenterPush] VERBOSE: -[MSPush didRegisterForRemoteNotificationsWithDeviceToken:]/298 Registering for push notifications has been finished successfully
2018-10-02 09:00:38.379 Internal.Passport.iOS[2843:1011984] [AppCenter] DEBUG: -[MSChannelUnitDefault enqueueItem:]_block_invoke/195 Saving log, type: pushInstallation.
Thread started: <Thread Pool> #9
2018-10-02 09:00:41.012 Internal.Passport.iOS[2843:1012006] [AppCenter] DEBUG: -[MSChannelUnitDefault flushQueue]_block_invoke/278 Sending 1/1 log, group Id: AppCenter, batch Id: 8983FF71-B24F-42A7-AA72-120C2B958462, session Id: (null), payload:
{
  "device" : {
    "appVersion" : "2018.09.28",
    "appBuild" : "2018.09.2801",
    "osName" : "iOS",
    "timeZoneOffset" : -240,
    "wrapperSdkVersion" : "1.9.0",
    "osVersion" : "12.0",
    "wrapperRuntimeVersion" : "11.2.0",
    "locale" : "en_CA",
    "wrapperSdkName" : "appcenter.xamarin",
    "appNamespace" : "com.nhci.internal.passport",
    "osBuild" : "16A366",
    "sdkName" : "appcenter.ios",
    "oemName" : "Apple",
    "sdkVersion" : "1.9.0",
    "model" : "iPad7,5",
    "screenSize" : "1536x2048"
  },
  "timestamp" : "2018-10-02T13:00:37.555Z",
  "type" : "startService",
  "services" : [
    "Push"
  ]
}
2018-10-02 09:00:41.014 Internal.Passport.iOS[2843:1012006] [AppCenter] VERBOSE: -[MSAppCenterIngestion createRequest:appSecret:]/94 URL: https://in.appcenter.ms/logs?api-version=1.0.0
2018-10-02 09:00:41.014 Internal.Passport.iOS[2843:1012006] [AppCenter] VERBOSE: -[MSAppCenterIngestion createRequest:appSecret:]/96 Headers: Install-ID = 7EFF6D73-0355-4374-8AE3-770A64B4E97E, App-Secret = ****************************8b9e4d42, Content-Type = application/json
2018-10-02 09:00:41.771 Internal.Passport.iOS[2843:1012004] [AppCenter] DEBUG: -[MSChannelUnitDefault flushQueue]_block_invoke/278 Sending 1/1 log, group Id: Push, batch Id: 32FAA5CE-3E3A-4C57-8EBE-0EADE61AC80F, session Id: (null), payload:
{
  "device" : {
    "appVersion" : "2018.09.28",
    "appBuild" : "2018.09.2801",
    "osName" : "iOS",
    "timeZoneOffset" : -240,
    "wrapperSdkVersion" : "1.9.0",
    "osVersion" : "12.0",
    "wrapperRuntimeVersion" : "11.2.0",
    "locale" : "en_CA",
    "wrapperSdkName" : "appcenter.xamarin",
    "appNamespace" : "com.nhci.internal.passport",
    "osBuild" : "16A366",
    "sdkName" : "appcenter.ios",
    "oemName" : "Apple",
    "sdkVersion" : "1.9.0",
    "model" : "iPad7,5",
    "screenSize" : "1536x2048"
  },
  "timestamp" : "2018-10-02T13:00:38.380Z",
  "type" : "pushInstallation",
  "pushToken" : "f037f0efbcff576c287fa0c93e599f640546b66b0384d79b6ca2165820780b1b"
}
2018-10-02 09:00:41.773 Internal.Passport.iOS[2843:1012004] [AppCenter] VERBOSE: -[MSAppCenterIngestion createRequest:appSecret:]/94 URL: https://in.appcenter.ms/logs?api-version=1.0.0
2018-10-02 09:00:41.774 Internal.Passport.iOS[2843:1012004] [AppCenter] VERBOSE: -[MSAppCenterIngestion createRequest:appSecret:]/96 Headers: Install-ID = 7EFF6D73-0355-4374-8AE3-770A64B4E97E, App-Secret = ****************************8b9e4d42, Content-Type = application/json
2018-10-02 09:00:42.002 Internal.Passport.iOS[2843:1011984] [AppCenter] VERBOSE: -[MSHttpIngestion sendCallAsync:]_block_invoke/302 HTTP response received with status code=200 and payload=CorrelationId: fdb21bb3-e707-459b-8c6d-bc2bbd32c040  ReasonCode: Success 
2018-10-02 09:00:42.003 Internal.Passport.iOS[2843:1012004] [AppCenter] DEBUG: -[MSChannelUnitDefault flushQueue]_block_invoke/308 Log(s) sent with success, batch Id:8983FF71-B24F-42A7-AA72-120C2B958462.
2018-10-02 09:00:42.003 Internal.Passport.iOS[2843:1011984] [AppCenter] INFO: -[MSHttpIngestion call:completedWithResult:]/359 Removed call id:8983FF71-B24F-42A7-AA72-120C2B958462 from pending calls:{
    "32FAA5CE-3E3A-4C57-8EBE-0EADE61AC80F" = "<MSIngestionCall: 0x2813d0140>";
}
2018-10-02 09:00:42.020 Internal.Passport.iOS[2843:1012004] [AppCenter] VERBOSE: -[MSLogDBStorage deleteLogsFromDBWithColumnValues:columnName:]/324 Deletion of log(s) by id with value(s) '133' succeeded.
2018-10-02 09:00:42.229 Internal.Passport.iOS[2843:1012006] [AppCenter] VERBOSE: -[MSHttpIngestion sendCallAsync:]_block_invoke/302 HTTP response received with status code=200 and payload=CorrelationId: 853b7232-9c4e-491b-8863-111ec6270dc2  ReasonCode: Success 
2018-10-02 09:00:42.230 Internal.Passport.iOS[2843:1011986] [AppCenter] DEBUG: -[MSChannelUnitDefault flushQueue]_block_invoke/308 Log(s) sent with success, batch Id:32FAA5CE-3E3A-4C57-8EBE-0EADE61AC80F.
2018-10-02 09:00:42.230 Internal.Passport.iOS[2843:1012006] [AppCenter] INFO: -[MSHttpIngestion call:completedWithResult:]/359 Removed call id:32FAA5CE-3E3A-4C57-8EBE-0EADE61AC80F from pending calls:{
}
2018-10-02 09:00:42.251 Internal.Passport.iOS[2843:1011986] [AppCenter] VERBOSE: -[MSLogDBStorage deleteLogsFromDBWithColumnValues:columnName:]/324 Deletion of log(s) by id with value(s) '134' succeeded.
Thread finished: <Thread Pool> #5
The thread 0x5 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #9
The thread 0x9 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #6
The thread 0x6 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #8
The thread 0x8 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #3
Thread started: <Thread Pool> #10
The thread 0x3 has exited with code 0 (0x0).
2018-10-02 09:02:03.012 Internal.Passport.iOS[2843:1011954] [AppCenterPush] VERBOSE: -[MSPush didReceiveRemoteNotification:fromUserNotification:]/372 User info for notification was forwarded to Push: {
    aps =     {
        alert =         {
            body = Test;
            title = Test;
        };
        sound = "ding.caf";
    };
    "mobile_center" =     {
        NotificationTypeCode = PushNotification;
        Code = c8;
        SoundPlay = "ding.caf";
    };
}
2018-10-02 09:02:03.012 Internal.Passport.iOS[2843:1011954] [AppCenterPush] DEBUG: -[MSPush didReceiveRemoteNotification:fromUserNotification:]/425 Notification received.
Title: Test
Message:Test
Custom data: {
    NotificationTypeCode = PushNotification;
    Code = c8;
    SoundPlay = "ding.caf";
}
Thread finished: <Thread Pool> #4
The thread 0x4 has exited with code 0 (0x0).
Thread started: <Thread Pool> #11
Thread started: <Thread Pool> #12
2018-10-02 09:02:29.934 Internal.Passport.iOS[2843:1011954] [AppCenterPush] VERBOSE: -[MSPush didReceiveRemoteNotification:fromUserNotification:]/372 User info for notification was forwarded to Push: {
    aps =     {
        alert =         {
            body = Test;
            title = Test;
        };
        sound = "ding.caf";
    };
    "mobile_center" =     {
        NotificationTypeCode = PushNotification;
        Code = c8;
        SoundPlay = "ding.caf";
    };
}
2018-10-02 09:02:29.935 Internal.Passport.iOS[2843:1011954] [AppCenterPush] DEBUG: -[MSPush didReceiveRemoteNotification:fromUserNotification:]/425 Notification received.
Title: Test
Message:Test
Custom data: {
    NotificationTypeCode = PushNotification;
    Code = c8;
    SoundPlay = "ding.caf";
}
Thread started:  #13
Thread started: <Thread Pool> #14
Thread started:  #15
Thread finished: <Thread Pool> #10
Thread started: <Thread Pool> #16
The thread 0xa has exited with code 0 (0x0).
Thread finished: <Thread Pool> #12
The thread 0xc has exited with code 0 (0x0).
achocron commented 6 years ago

Is the web portal showing successes or failures for the push notifications that aren't being received? You should see a success rate in the detail view of the push notification in the UI.

eliaspuurunen commented 6 years ago

@achocron yes - the notifications appear on the device as well.

To clarify - the notifications are being displayed on the device (iPad) and can be tapped, but after the 1st time the event fires, the event from the AppCenter Push SDK will no longer fire.

achocron commented 6 years ago

Got it. I can't seem to reproduce - on my end, the event is fired each time I tap a new notification. Are you subscribing to the event before or after you start App Center?

eliaspuurunen commented 6 years ago

@achocron before I start AppCenter. Should we try after/should we only subscribe after?

        protected override void OnStart()
        {
            if (!AppCenter.Configured)
            {
                Push.PushNotificationReceived += OnGotPush;
            }

            //AppCenter.LogLevel = LogLevel.Verbose;
            // Actual keys omitted for privacy

            AppCenter.Start("android=00000000-0000-0000-0000-000000000000;" +
                  "uwp=00000000-0000-0000-0000-000000000000;" +
                  $"ios={iOSKey}",
                  typeof(Push));

            this.MainPage = new NavigationPage(new LoginPage());

        }
eliaspuurunen commented 5 years ago

@achocron Additional information: we are also using a plugin to show local notifications.

https://github.com/EgorBo/Toasts.Forms.Plugin/tree/master/Toasts.Forms.Plugin.iOS

This morning I removed any initialization calls to the plugin from our code. AppCenter Push is now working exactly as expected. It appears there is a conflict between this plugin and AppCenter Push.

  1. AppCenter.Push receives a push notification in the foreground.
  2. My code forwards this to the local notification plugin (Toasts.Forms.Plugin) to display the notification.
  3. The notification is displayed.
  4. Another push notification is received. It is displayed, but does not fire AppCenter.Push's events nor is it handled within the app.

Question: if the app is in the foreground, how should we handle display of notifications? Is there a suggested plugin to use for Xamarin Forms that will not break AppCenter.Push?

In the following file, it appears that once the plugin is called to display a local notification, the notification center delegate is replaced with the plugin's implementation.

https://github.com/EgorBo/Toasts.Forms.Plugin/blob/master/Toasts.Forms.Plugin.iOS/UNNotificationManager.cs

// Line 20 of Toasts.Forms.Plugin/Toasts.Forms.Plugin.iOS/UNNotificationManager.cs
            var notificationCenter = UNUserNotificationCenter.Current;
            // Code omitted for brevity
            notificationCenter.Delegate = new UserNotificationCenterDelegate(id, (identifier, notificationResult) =>
            {
                lock (_lock)
                    if (_resetEvents?.ContainsKey(identifier) == true && _eventResult?.ContainsKey(identifier) == false)
                    {
                        _eventResult.Add(identifier, notificationResult);
                        _resetEvents[identifier].Set();
                    }
            }, options.ClearFromHistory, options.AllowTapInNotificationCenter);
eliaspuurunen commented 5 years ago

Further update: we have been using a badly-outdated version of the Toast.Forms.Plugin plugin. We're running some new tests to see if the latest has conflicts.

Update: After migrating to the latest version of Toast.Forms.Plugin, the issue is still occurring.

achocron commented 5 years ago

So it would indeed seem that the plugin is replacing the App Center delegate with its own. Unfortunately, I don't have a recommendation as to what the best plugin for this scenario is.

I also found this issue: https://github.com/EgorBo/Toasts.Forms.Plugin/issues/164. It seems to be an issue within the plugin that other, non App Center users have faced.

eliaspuurunen commented 5 years ago

@achocron for the time being, we've ripped out the Toasts plugin and used the AppCenter.Push guidance to handle foreground notifications another way.

We do still have use cases where displaying a native local notification would be useful. Any guidance re: local notifications, Xamarin.Forms, and AppCenter.Push would be most appreciated.

achocron commented 5 years ago

At the moment, I'm having problems with my certificates so I can't test this out myself, but I'd try adding something like this to the iOS project:

Create a new class:

public class NotificationDelegate : UNUserNotificationCenterDelegate
{
  public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
  {
    completionHandler();
  }

  public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
  {
    completionHandler(UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Alert);
  }
}

Add this to the AppDelegate class:

public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
{
  // Add this before Xamarin.Forms.Forms.Init()
  UserNotifications.UNUserNotificationCenter.Current.Delegate = new NotificationDelegate();
  Xamarin.Forms.Forms.Init();

  // Other initialization code...
}

You will still be able to use Push.PushNotificationReceived += OnGotPush;. When App Center Push sets its custom delegate, it should detect that you have added your own custom delegate already, and invoke it when it receives a notification.

I referred to this Stack Overflow question; you may find it useful as well.

MatkovIvan commented 5 years ago

This delegate is documented in the AppCenter docs, there are some additional details for proper use. But I guess it isn't an initial case.

iamclement commented 5 years ago

@eliaspuurunen The UserNotificationCenterDelegate delegate and its WillPresentNotification form the Toast library is most probably eclipsing the DidReceiveRemoteNotification method of the UIApplicationDelegate used by the SDK. WillPresentNotification wins over DidReceiveRemoteNotification when both are implemented. A solution is to implement and register your own UserNotificationCenterDelegate and call the SDK push callback manually from there as mentioned in the documentation @MatkovIvan linked. Then we still have to make sure the Toast library handle the scenario where the customer registers his own UserNotificationCenterDelegate delegate.

I'll go ahead and close this issue for now, I'll create a bug on the AppCenter side to see if we can circumvent that situation from the SDK perspective.

Thanks for reporting this!