JohnWick
JohnWick

Reputation: 261

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? 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 
            }

Upvotes: 0

Views: 1033

Answers (2)

Asceticsoft
Asceticsoft

Reputation: 71

Check your MainActivity OnRequestPermissionsResult(). Comment one by one another receivers of permissions and run. You will find the culprit. Good luck!

Upvotes: 0

Leo Zhu
Leo Zhu

Reputation: 14991

You should add items in Info.plist

Refer to the link :App pop Up saying "... Would like to access your (Camera, location, photos, etc)"

and document :Apple Document

Upvotes: 0

Related Questions