2

I have an Xamarin IOS project and I would like to create local notifications. For that I have to ask the user for permission. I have this code in the AppDelegate:

UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) =>
            {
                // Handle approval
            });

That works so far, but unfortunately the dialog from requesting the permissions is behind the splash screen. Therefore it looks for the user as if the app was stuck. If he clicks the home button then he can see the permission dialog.

I also tried to put it in the first view in the ViewDidLoad or the ViewDidLayoutSubviews Method. But the effect was the same.

How can I display the dialog properly?

Cœur
  • 37,241
  • 25
  • 195
  • 267
NPadrutt
  • 3,619
  • 5
  • 24
  • 60
  • You can try requesting in your app's very first screen instead of requesting in AppDelegate. – Glenn Posadas Oct 16 '17 at 08:22
  • In what method would you do that? I tried in the ViewDidLoad and ViewDidLayoutSubviews without success. – NPadrutt Oct 16 '17 at 08:31
  • How about in `viewDidAppear`? I have never experienced such kind of issue. Not sure but perhaps it's a Xamarin bug? I'm a native iOS developer, by the way. Just passed through since no one is commenting or answering in your question. – Glenn Posadas Oct 16 '17 at 14:44
  • Do you mean the permission dialog only shows in the background, not foreground? Will it show in the first view controller when the launch screen disappears? – Kevin Li Oct 17 '17 at 03:00
  • @Glenn the same in the ViewDidAppear method. But I'll try all of them again. Maybe I have more luck on the second try :) – NPadrutt Oct 17 '17 at 06:54
  • @kevin yes exactly. The issue is, that the first view controller isn't loaded, because it get stuck in the splash screen since it waits for an answer for the dialog. – NPadrutt Oct 17 '17 at 06:55
  • @NPadrutt, strange, the dialog will not block the main thread, why your first view controller will be blocked by the permission dialog? – Kevin Li Oct 17 '17 at 07:04
  • @Kevin das ist the big question. – NPadrutt Oct 24 '17 at 10:30
  • I havent encountered a problem like this. Usually you ask for permissions when you are going to do some work. And always handle if user rejects. – soan saini May 18 '18 at 00:31
  • Got this exact issue. Not sure what part of the lifecycle is calling for the permission yet because it's in a third party library – Frank Feb 16 '21 at 09:51

0 Answers0