Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

objective c - iOS 10 - App crashes To access photo library or device camera via UIImagePickerController

Below is my code to access photo library

-(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];
     }

}

And it aborts with

This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

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    

And I get Thread 10:EXC_BAD_INTRUCTION code=exc_i386_invop, Same code was working fine in iOS 9. Can someone help me to solve this issue. Thanks in Advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In iOS 10. You have to set privacy Setting for Camera & Photo Library.

Camera :

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

Photo Library:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...