iOS 10错误[访问] 使用UIImagePickerController时

问题描述:

我正在使用XCode 8并使用iOS 10.2 Beta进行测试。iOS 10错误[访问] <private>使用UIImagePickerController时

我已经添加了照片,PhotosUI和MobileCoreServices框架项目。

非常简单的代码:

#import <Photos/Photos.h> 
#import <PhotosUI/PhotosUI.h> 
#import <MobileCoreServices/MobileCoreServices.h> 

@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, PHLivePhotoViewDelegate> 

@property (strong, nonatomic) IBOutlet UIImageView *imageview; 

@end 

和实施:

- (IBAction)grab:(UIButton *)sender{ 
    UIImagePickerController *picker = [[UIImagePickerController alloc]init]; 
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    picker.allowsEditing = NO; 
    picker.delegate = self; 

    // make sure we include Live Photos (otherwise we'll only get UIImages) 
    NSArray *mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeLivePhoto]; 
    picker.mediaTypes = mediaTypes; 

    // bring up the picker 
    [self presentViewController:picker animated:YES completion:nil]; 
} 

只要我轻点按钮,该应用程序崩溃非常无用的错误:

[access] <private>

而已。没有其他的。

使用break语句时,应用程序似乎在“presentViewController”中崩溃。

这是一个全新的应用程序,我除了抓取按钮外没有任何其他用户界面。

此外,在iOS 9.3上测试,这工作正常。我是否错过了iOS 10中可能更改的内容?

+0

清洁,然后建立。如果没有变化,可能很容易成为Xcode 8或iOS 10 beta中的一个bug,Apple将在未来更新中解决该问题。我经常发现这种情况 - 如果它是最后一个测试版,或者是通用版发布,但它仍然无法正常工作,那么就是时候担心修复它了。 –

+1

是的,同样的问题,即使在清理和删除应用程序后:( –

+0

我不会强调它,这是一个测试版本,机会更可能是测试版本的问题,我建议在Xcode 7上开发,直到很多 –

您可能需要将NSPhotoLibraryUsageDescription放入您的plist中。 像

<key>NSPhotoLibraryUsageDescription</key> 
<string>$(PRODUCT_NAME) uses photos</string> 

检查所有使用说明here

+1

对不起,您是如何找到这个发布号码? –

+1

在iOS下载网站中,我刚刚解决了正确的UsageDescription项。 – rockdaswift

+0

谢谢,您的答案马上解决了问题!这是一个新的要求自iOS 10以来。欢迎来到Stack overflow btw! –

在iOS10,您访问诸如照相机,通讯录隐私敏感数据之前,等等,你必须要求的授权,或者当您访问them.Then Xcode中会记录您的应用程序会崩溃,如:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSContactsUsageDescription key with a string value explaining to the user how the app uses this data.

如何处理?

打开项目中名为info.plist的文件,右键单击它,打开为Source Code,将下面的代码粘贴到它。或者您可以打开info.plist默认为Property List,点击添加按钮,Xcode会在键盘⬆️和⬇️的帮助下输入Privacy -时为您提供完成提示。

<!-- Photo Library --> 
<key>NSPhotoLibraryUsageDescription</key> 
<string>$(PRODUCT_NAME) photo use</string> 

<!-- Camera --> 
<key>NSCameraUsageDescription</key> 
<string>$(PRODUCT_NAME) camera use</string> 

<!-- Microphone --> 
<key>NSMicrophoneUsageDescription</key> 
<string>$(PRODUCT_NAME) microphone use</string> 

<!-- Location --> 
<key>NSLocationUsageDescription</key> 
<string>$(PRODUCT_NAME) location use</string> 

<!-- Location When In Use --> 
<key>NSLocationWhenInUseUsageDescription</key> 
<string>$(PRODUCT_NAME) location use</string> 

<!-- Location Always --> 
<key>NSLocationAlwaysUsageDescription</key> 
<string>$(PRODUCT_NAME) always uses location </string> 

<!-- Calendars --> 
<key>NSCalendarsUsageDescription</key> 
<string>$(PRODUCT_NAME) calendar events</string> 

<!-- ⏰ Reminders --> 
<key>NSRemindersUsageDescription</key> 
<string>$(PRODUCT_NAME) reminder use</string> 

<!-- Contacts --> 
<key>NSContactsUsageDescription</key> 
<string>$(PRODUCT_NAME) contact use</string> 

<!-- Motion --> 
<key>NSMotionUsageDescription</key> 
<string>$(PRODUCT_NAME) motion use</string> 

<!-- Health Update --> 
<key>NSHealthUpdateUsageDescription</key> 
<string>$(PRODUCT_NAME) heath update use</string> 

<!-- Health Share --> 
<key>NSHealthShareUsageDescription</key> 
<string>$(PRODUCT_NAME) heath share use</string> 

<!-- ᛒ Bluetooth Peripheral --> 
<key>NSBluetoothPeripheralUsageDescription</key> 
<string>$(PRODUCT_NAME) Bluetooth Peripheral use</string> 

<!-- Media Library --> 
<key>NSAppleMusicUsageDescription</key> 
<string>$(PRODUCT_NAME) media library use</string> 

<!-- Siri --> 
<key>NSSiriUsageDescription</key> 
<string>$(PRODUCT_NAME) siri use</string> 

<!-- HomeKit --> 
<key>NSHomeKitUsageDescription</key> 
<string>$(PRODUCT_NAME) home kit use</string> 

<!-- SpeechRecognition --> 
<key>NSSpeechRecognitionUsageDescription</key> 
<string>$(PRODUCT_NAME) speech use</string> 

<!-- VideoSubscriber --> 
<key>NSVideoSubscriberAccountUsageDescription</key> 
<string>$(PRODUCT_NAME) tvProvider use</string> 

如果没有作品,试图索要背景:

记住你为什么问这个授权来写你的描述,<string></string>,或者您的应用程序之间将会被苹果拒绝授权:

<key>UIBackgroundModes</key> 
<array> 
    <!-- something you should use in background --> 
    <string>location</string> 
</array> 

还是去target -> Capabilities -> Background Modes -> open the background Modes

enter image description here

然后清理您的项目,运行它。

回到这里以获取更多信息:iOS10AdaptationTips

+2

我用照片无处,苹果拒绝我的应用程序,任何想法?我也检查所有的豆荚项目 –

+0

@RaheelSadiq记得写你的描述为什么你要求这个授权,''和''之间,否则你的应用程序将被苹果拒绝。 – ElonChan

iOS中10,你需要,如果你正在使用相机或照片库应用程式中加入下面的图片中提到的关键

.plist image

您需要添加新的隐私设置,你的Info.plist 。

不要忘记添加描述为什么应用程序需要访问服务的值。

enter image description here

在iOS系统10,苹果已经改变了你如何可以访问任何用户隐私数据的类型。

您需要添加隐私 - 照片库使用说明您的应用程序的关键Info.plist及其使用信息。

欲了解更多信息,请找到下面的GIF。

GIF

或者,如果你想通过info.plist添加,那么你需要添加NSPhotoLibraryUsageDescription关键。

只需在info.plist下面复制并粘贴字符串即可。

<key>NSPhotoLibraryUsageDescription</key> 
<string>Take the photo</string> 

请在下方找到GIF以获取更多信息。

GIF

+1

以及 NSCameraUsageDescription拍照