且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从iOS 8设置启用相机访问时,应用程序崩溃

更新时间:2023-01-05 21:32:02

第一次访问相机时操作系统将自动显示权限提示。无论用户是允许还是拒绝提示,您的应用都将继续运行。如果用户在某个时刻更改了地址簿,日历,提醒,相机或照片权限,则iOS将 SIGKILL 该应用。它采取此操作以确保应用程序不再拥有其拥有的任何先前授权的数据。当用户从设置应用程序移回第三方应用程序时,它将从头开始启动,现在具有拒绝授权状态。由于这种行为,我有两个建议:

The first time you access the Camera the OS will automatically show the permission prompt. Whether the user allows or denies the prompt, your app will continue running. If the user at some point changes the Address Book, Calendars, Reminders, Camera, or Photos permissions, iOS will SIGKILL the app. It takes this action to ensure that the app no longer has any previously authorized data in its possession. When the user moves from the Settings app back to the third-party app, it launches from scratch and now has the Denied authorization status. As a result of this behavior, I have two recommendations:


  1. 检测权限何时被拒绝并提供一些解释该权限的UI用户需要切换设置应用程序权限。在iOS 8中,您可以使用 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]] 将它们直接带到您应用的条目。

  1. Detect when the permission is denied and present some UI that explaining that the user needs to toggle the Settings app permission. In iOS 8 you can take them directly to your app's entry with [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]].

实施某种状态恢复,以便当应用程序终止并重新启动时,它会将用户返回到先前可见的视图/功能。

Implement some sort of state restoration so that when the app is terminated and relaunched it will return the user to the view/feature that was previously visible.

来源(需要开发者帐户)