【问题标题】:iOS 10 - App crashes To access photo library or device camera via UIImagePickerControlleriOS 10 - 应用程序崩溃通过 UIImagePickerController 访问照片库或设备相机
【发布时间】:2017-02-05 22:05:08
【问题描述】:

以下是我访问照片库的代码

-(void)click_gallery
{

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
     {

    UIImagePickerController *imgPicker= [[UIImagePickerController alloc] init];
    UIColor* color = [UIColor colorWithRed:46.0/255 green:127.0/255 blue:244.0/255 alpha:1];
    [imgPicker.navigationBar setTintColor:color];
    imgPicker.delegate = self;
    imgPicker.allowsEditing = YES;
    imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:imgPicker animated:NO completion:Nil];
     }

}

它会中止

此应用尝试在没有使用说明的情况下访问隐私敏感数据。应用的 Info.plist 必须包含一个 NSCameraUsageDescription 键和一个字符串值,向用户解释应用如何使用这些数据。

libsystem_kernel.dylib`__pthread_kill:
    0x109955efc <+0>:  movl   $0x2000148, %eax          ; imm = 0x2000148 
    0x109955f01 <+5>:  movq   %rcx, %r10
    0x109955f04 <+8>:  syscall 
->  0x109955f06 <+10>: jae    0x109955f10               ; <+20>
    0x109955f08 <+12>: movq   %rax, %rdi
    0x109955f0b <+15>: jmp    0x1099507cd               ; cerror_nocancel
    0x109955f10 <+20>: retq   
    0x109955f11 <+21>: nop    
    0x109955f12 <+22>: nop    
    0x109955f13 <+23>: nop    

我得到 线程 10:EXC_BAD_INTRUCTION code=exc_i386_invop, 相同的代码在 iOS 9 中运行良好。有人可以帮我解决这个问题。提前致谢。

【问题讨论】:

    标签: ios objective-c uiimagepickercontroller ios10 xcode8


    【解决方案1】:

    iOS 10 中。您必须为相机和照片库设置隐私设置。

    相机:

    Key       :  Privacy - Camera Usage Description   
    Value     :  $(PRODUCT_NAME) camera use
    

    照片库:

    Key       :  Privacy - Photo Library Usage Description    
    Value     :  $(PRODUCT_NAME) photo use
    

    【讨论】:

      【解决方案2】:

      IOS 10 现在需要用户权限才能访问媒体库、照片、 相机和其他类似的硬件。解决方案是添加 他们进入 info.plist 的键,并为用户描述我们的情况 使用他们的数据,iOS 已经需要权限才能访问 麦克风、摄像头和媒体库较早(iOS6、iOS7),但从 iOS10 如果您不提供原因说明,应用程序将崩溃 正在请求许可。

      在 plist 文件中添加以下键值。

      您可以在 Info.plist 文件中指定所有可可键的列表

      照片:

      Key       :  Privacy - Photo Library Usage Description    
      Value   :  $(PRODUCT_NAME) photo use
      

      麦克风:

      Key        :  Privacy - Microphone Usage Description    
      Value    :  $(PRODUCT_NAME) microphone use
      

      相机:

      Key       :  Privacy - Camera Usage Description   
      Value   :  $(PRODUCT_NAME) camera use
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-24
        • 2017-04-15
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多