切换访问相机和照片时崩溃 [英] Crash when toggling access to Camera and Photos

查看:103
本文介绍了切换访问相机和照片时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集合视图(标准流程布局),其中第一个单元格正在显示实时摄像机供稿,其余单元格正在使用iOS 8的新Photos框架显示用户库中的照片.一切都能呈现并发挥出色.

I have a collection view (standard flow layout) where the first cell is displaying a live camera feed, and the rest of the cells are displaying photos from the user's library using iOS 8's new Photos Framework. Everything renders and works great.

第一次打开时,系统会提示我按预期访问照相机和照片库.如果我对任何一个提示选择是或否,则我的应用程序运行正常.

When opening for the first time, I'm prompted for access to the Camera and to the Photos library, as expected. My app behaves fine if I select yes or no for either of the prompts.

但是,如果我后台运行该应用程序,请进入设置">隐私">照片" |相机"并切换访问权限,我的应用程序会崩溃.连接到Xcode时,我没有收到有关应用崩溃的任何反馈.

However, if I background the app, go into Settings > Privacy > Photos|Camera and toggle access, my app crashes. When connected to Xcode, I don't get any feedback for why the app is crashing.

不幸的是, Apple的照片框架示例应用确实可以同样的事情.

Unfortunately, Apple's Photos Framework examples app does the same thing.

如何防止这种情况发生?我已经在PHPhotoLibrary上订阅了AVCaptureDeviceWasConnectedNotificationAVCaptureDeviceWasDisconnectedNotificationregisterChangeObserver的通知,但这些通知似乎从未被调用.

How can I prevent this from happening? I've subscribed to notifications for AVCaptureDeviceWasConnectedNotification, AVCaptureDeviceWasDisconnectedNotification, and registerChangeObserver on PHPhotoLibrary but those never seem to get called.

同样,这是使用Apple的示例应用程序和模拟器的步骤:

Again, here are the steps using Apple's Sample app and the Simulator:

  1. 在模拟器中,转到设置>常规>重置>重置位置&隐私
  2. 运行应用
  3. 允许应用访问您的照片库
  4. 将示例应用程序设为背景并打开设置"
  5. 转到隐私">照片",然后将设置关闭
  6. 观看Xcode崩溃

在步骤3中,如果您拒绝对照片的访问,而在步骤5中启用访问,则该应用程序也将崩溃.

In step 3, if you decline access to your photos, and in step 5, enable access, the app will also crash.

推荐答案

这本身并不是崩溃.更改隐私标记后,iOS系统会终止请求访问照片库的所有应用程序系统范围(包括Apple System Apps).

It's not a crash per se. The iOS system terminates every app system wide that has requested access to the Photo Library when that privacy flag is changed (including Apple System Apps).

这是由于iOS 6中的隐私更改引起的.请参阅WWDC 2012会话中第24页的 iOS和OS X中的隐私支持.

This originates due to a privacy change made in iOS 6. Look at page 24 in the WWDC 2012 session on Privacy Support in iOS and OS X.

这篇关于切换访问相机和照片时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆