简体   繁体   English

如何在 iOS 中再次请求照片库权限

[英]How can you request photo gallery permissions in iOS a second time

In my iOS app I am accessing the user's photo gallery.在我的 iOS 应用程序中,我正在访问用户的照片库。 The first time the user does this, it asks them for permission.用户第一次这样做时,它会请求他们的许可。 Some of my users have reported getting a crash this first time due to the permission request, but it works fine on subsequent tries.我的一些用户报告说,由于权限请求,这是第一次崩溃,但在随后的尝试中运行良好。

To be able to test this on my own, I need to be able remove the permission from my iPad and have it prompt again.为了能够自己测试这个,我需要能够从我的 iPad 中删除权限并让它再次提示。 Is there a way to do this either through the iPad/iPhone itself or through code?有没有办法通过 iPad/iPhone 本身或通过代码来做到这一点?

Run the Settings app.运行设置应用程序。 Go to General, then Reset.转到常规,然后重置。 Tap on Reset Location & Privacy.点击重置位置和隐私。 This will reset all of your location and privacy settings, not just for your test app.这将重置您的所有位置和隐私设置,而不仅仅是您的测试应用程序。 But you are doing this on a development device so that should be OK.但是您是在开发设备上执行此操作,因此应该没问题。 This works in the Simulator too.这也适用于模拟器。

In iOS 7+, you can go into Settings > Privacy > Photos and explicitly enable or disable access for individual apps.在 iOS 7+ 中,您可以进入“设置”>“隐私”>“照片”并明确启用或禁用对单个应用程序的访问。

This is much better than resetting your entire device privacy settings!这比重置整个设备的隐私设置要好得多!

Another way is to temporary change Bundle Identifier (CFBundleIdentifier) in Info.plist.另一种方法是临时更改Info.plist 中的Bundle Identifier(CFBundleIdentifier)。 System will treat such app as a new separate app and will display "would like to access your Photos" alert.系统会将此类应用程序视为一个新的独立应用程序,并会显示“想要访问您的照片”警报。 Don't forget to revert CFBundleIdentifier after you end testing.不要忘记在结束测试后恢复 CFBundleIdentifier。

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

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