简体   繁体   English

在Xamarin iOS中拒绝位置权限时,应用崩溃

[英]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". 我得到了“ 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? 在android中,它的工作正常。我是否需要更新权限插件或更改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 
            }

You should add items in Info.plist 您应该在Info.plist中添加项目

Refer to the link : App pop Up saying "... Would like to access your (Camera, location, photos, etc)" 请参阅链接: 应用程序弹出窗口显示“ ...想要访问您的(相机,位置,照片等)”

and document : Apple Document 和文件: Apple文件

Check your MainActivity OnRequestPermissionsResult(). 检查您的MainActivity OnRequestPermissionsResult()。 Comment one by one another receivers of permissions and run. 逐一评论权限接收者并运行。 You will find the culprit. 您会发现罪魁祸首。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM