Calling LocalNotificationCenter.RequestNotificationPermissionAsync().GetAwaiter().GetResult() blocks the thread and iOS app launch
See original GitHub issueDescribe 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:
- Created a year ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @thudugala, I can confirm LocalNotificationCenter.RequestNotificationPermission() in v10.0.2 works as expected. Thanks
LocalNotificationCenter.ResetApplicationIconBadgeNumber(uiApplication);