Forum Xamarin.Forms

App crash when denied location permission in Xamarin iOS

i need to have location in my app and app got crash when user denied the location permission by clicking "Don't Allow". i got "System.Reflection.TargetInvocationException". but once i again start again even on that time the permission is denied its not crashing . in android its working fine .Do i need to update permission plugin or change in info.Plist? i gave all three permission in info.Plist for Location . here is my code .

  var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
        if (status != PermissionStatus.Granted)
            if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                await Application.Current.MainPage.DisplayAlert("Location denied", "app needs access to location for this operation.", "OK");

            var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
            status = results[Permission.Location];
        if (status == PermissionStatus.Granted)
              // do something
        else if (status != PermissionStatus.Unknown)
              // Crash when user denied permission 


  • Luis_dmLuis_dm USMember ✭✭✭

    Can you show us your info.plist, please?

  • LandLuLandLu Member, Xamarin Team Xamurai

    What detailed code throws this exception? If the user denied this permission, your code will always run into your first if statement.
    I think it is not the issue of the CrossPermissions plugin. Maybe it is your code below the status = results[Permission.Location]; causes the issue.

Sign In or Register to comment.