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

Xamarin Forms iOS UI Freeze After Permissions Dialog #192

Closed chrisparkeronline closed 4 years ago

chrisparkeronline commented 4 years ago

Using the latest version of both OneSignal and Xamarin Forms 4.5.0.617, the UI freezes. Selecting the notifications permission dialog that is presented to user when app loads for the first time. Regardless what option is chosen, my UI is no longer responsive. The app has to be shutdown then restarted and everything works as coded.

It's as if the permissions dialog is still blocking the UI even after it visually is removed.

Environment Xamarin Forms v 4.5.0.617 OneSignal v 3.8.1 Test Device: iPhone11,8 (13.3.1)

Steps to Reproduce Issue:

  1. Start app in debug or release mode for first time.
  2. Tap accept or decline when asked for notification permissions.
  3. Tap on any control within the view such as a entry or button.

Log Information Verbose information outputed to the log window within Visual Studio Mac

2020-04-10 19:12:42.633 StoryData.Mobile.iOS[26379:16374565] VERBOSE: network response (OSRequestGetIosParams): {
    fba = 1;
    outcomes =     {
        direct =         {
            enabled = 0;
        };
        indirect =         {
            enabled = 0;
            "notification_attribution" =             {
                limit = 10;
                "minutes_since_displayed" = 60;
            };
        };
        unattributed =         {
            enabled = 0;
        };
    };
    "receive_receipts_enable" = 1;
    "uses_provisional_auth" = 0;
}
[PLCrashReport] MSplcrash_log_writer_init:352: Could not retreive parent process name: Operation not permitted
2020-04-10 19:12:42.802 StoryData.Mobile.iOS[26379:16374492] VERBOSE: ONESIGNAL setOneSignalDelegate CALLED: (null)
2020-04-10 19:12:42.802 StoryData.Mobile.iOS[26379:16374492] VERBOSE: ONESIGNAL setOneSignalDelegate CALLED: <AppDelegate: 0x28164e640>
2020-04-10 19:12:42.804 StoryData.Mobile.iOS[26379:16374492] VERBOSE: oneSignalApplicationDidBecomeActive
2020-04-10 19:12:42.804 StoryData.Mobile.iOS[26379:16374492] VERBOSE: Application Foregrounded started
2020-04-10 19:12:42.804 StoryData.Mobile.iOS[26379:16374492] VERBOSE: cancelFocusCall of {
}
2020-04-10 19:12:42.847 StoryData.Mobile.iOS[26379:16374492] VERBOSE: oneSignalApplicationWillResignActive
2020-04-10 19:12:42.847 StoryData.Mobile.iOS[26379:16374492] VERBOSE: Application Backgrounded started
2020-04-10 19:12:42.848 StoryData.Mobile.iOS[26379:16374492] VERBOSE: TimeProcessor <OSUnattributedFocusTimeProcessor: 0x2810040a0> for session attributed 0
2020-04-10 19:12:42.848 StoryData.Mobile.iOS[26379:16374492] VERBOSE: sendOnFocusCall unattributed with totalTimeActive -1.000000
2020-04-10 19:12:42.848 StoryData.Mobile.iOS[26379:16374492] VERBOSE: OSBaseFocusTimeProcessor hasMinSyncTime getMinSessionTime: 60 activeTime: -1.000000
2020-04-10 19:12:42.848 StoryData.Mobile.iOS[26379:16374492] VERBOSE: unattributed session saveUnsentActiveTime -1.000000
2020-04-10 19:12:51.592 StoryData.Mobile.iOS[26379:16374492] VERBOSE: updateNotificationTypes called: 15
2020-04-10 19:12:51.592 StoryData.Mobile.iOS[26379:16374492] VERBOSE: startedRegister: 1
2020-04-10 19:12:51.983 StoryData.Mobile.iOS[26379:16374492] VERBOSE: oneSignalApplicationDidBecomeActive
2020-04-10 19:12:51.983 StoryData.Mobile.iOS[26379:16374492] VERBOSE: Application Foregrounded started
2020-04-10 19:12:51.983 StoryData.Mobile.iOS[26379:16374492] VERBOSE: cancelFocusCall of {
    "NOT_ATTRIBUTED" = "<OSUnattributedFocusTimeProcessor: 0x2810040a0>";
}

Code

public App()
        {
            Xamarin.Forms.Device.SetFlags( new[] {
                "CarouselView_Experimental",
                "IndicatorView_Experimental",
                "SwipeView_Experimental"
            } );
            InitializeComponent();

            MainPage = GetLoginPage();

            //Setup one signal.
            OneSignal.Current.UserDidProvidePrivacyConsent(true);
            OneSignal.Current.SetLocationShared(false);
            OneSignal.Current.StartInit("[My Id]")
                            .UnsubscribeWhenNotificationsAreDisabled(true)
                            .HandleNotificationReceived(App.HandleNotificationReceived)
                            .HandleNotificationOpened(App.HandleNotificationOpened)
                            .InFocusDisplaying(OSInFocusDisplayOption.None)
                            .EndInit();
            OneSignal.Current.SetLogLevel(LOG_LEVEL.VERBOSE, LOG_LEVEL.NONE);
        }
mikechoch commented 4 years ago

Thank you for reporting this, will put some time aside to try to reproduce this and find a solution for you! Can you confirm with the location permission prompt if this happens also?

chrisparkeronline commented 4 years ago

Hello,

Yes calling OneSignal.Current.PromptLocation(); dialog causes the interface to freeze as well.

chrisparkeronline commented 4 years ago

I did some more investigating. Change the code to this so that I could call registration from other places in the code;

OneSignal.Current.SetLocationShared(false);
OneSignal.Current.StartInit("[My Id]")
    .UnsubscribeWhenNotificationsAreDisabled(true)
    .HandleNotificationReceived(HandleNotificationReceived)
    .HandleNotificationOpened(HandleNotificationOpened)
    .InFocusDisplaying(OSInFocusDisplayOption.None)
    .Settings(new Dictionary<string, bool>() {
        { IOSSettings.kOSSettingsKeyAutoPrompt, false },
        { IOSSettings.kOSSettingsKeyInAppLaunchURL, false } })
    .EndInit();

Using the kOSSettingsKeyAutoPrompt turns off the auto prompting. I can confirm, no matter where I call "OneSignal.Current.RegisterForPushNotifications();" the prompt freezes that contentpage's controls every time.

The prompt does set the "subscribed" setting to true. So it is posting the information back to your servers.

chrisparkeronline commented 4 years ago

Sorry for the rapid fire of posts. Right after I posted the last message I put this following code in the "OnAppearing" method a contentpage and it worked fine.

protected override void OnAppearing()
        {
            base.OnAppearing();

            MainThread.BeginInvokeOnMainThread(() =>
            {
                OneSignal.Current.RegisterForPushNotifications();
            });
        }
mikechoch commented 4 years ago

More information the better, thank you for all of this!

chrisparkeronline commented 4 years ago

Hi, I can't speak for anyone else but I think this ticket should be closed, here is why. When the app launches the StartInit method is called. This causes iOS to ask for the notifications permissions, as it should. I just found out that iOS puts the app in sleep mode (OnSleep is called) until the user responds. Once the user responds, the app resumes (OnResume is called). In my OnResume I had a task that runs that blocks the thread, causing my app to freeze.

BOTTOM LINE IT IS MY CODE. I'm man enough to admit that I made the mistake, not OneSignal! Sorry team @mikechoch @rgomezp

rgomezp commented 4 years ago

Thanks for the response @chrisparkeronline Enjoy!