question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult() blocks the thread and iOS app launch

See original GitHub issue

Describe the bug

The Xamarin.Forms setup doc indicates you should call LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult() in the FinishedLaunching override, but this blocks the app from loading as the thread is being blocked. Is there a synchronous version of this method if it must be called for iOS apps?

To Reproduce

Add:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            // Ask the user for permission to show notifications on iOS 10.0+ at startup.
            // If not asked at startup, the user will be asked when showing the first notification.
            LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult();

            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }

Expected behavior iOS app to load as normal

Platform (please complete the following information):

  • OS: 15.5

Smartphone (please complete the following information):

  • Device: [e.g. iPhone13]
  • OS: [e.g. iOS15.5]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
SandipAhluwaliacommented, Aug 24, 2022

Hi @thudugala, I can confirm LocalNotificationCenter.RequestNotificationPermission() in v10.0.2 works as expected. Thanks

1reaction
mos379commented, Aug 22, 2022

public override void WillEnterForeground(UIApplication uiApplication) { LocalNotificationCenter.ResetApplicationIconBadgeNumber(); base.WillEnterForeground(uiApplication); } should be

LocalNotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is Task.Result the same as .GetAwaiter.GetResult()?
GetAwaiter().GetResult() is more equivalent to Task.Wait and Task.Result (in that all three will block synchronously and have the potential for ...
Read more >
Why is .GetAwaiter().GetResult() bad in C#?
GetAwaiter() returns a TaskAwaiter object and if we peek into the documentation it ... The thread doing the work is now blocked due...
Read more >
Is GetAwaiter().GetResult() cause a deadlock ? #64849
I have .net 6 web application and i'm in situation that i'm forced to call async method from sync method. I read two...
Read more >
TIL GetAwaiter() don't start a Task : r/csharp
So I thought I just use the task returned an call GetAwaiter().GetResult() and ... Run doesn't prevent blocking a thread in the threadpool....
Read more >
A Tour of Task, Part 6: Results
GetAwaiter().GetResult();. In general, I try my best to avoid synchronously blocking on an asynchronous task. However, there ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found