Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using XCode 8 and testing with iOS 10.2 Beta.

I have added the Photos, PhotosUI and MobileCoreServices frameworks to project.

Very simple code:

#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

and implementation:

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

As soon as I tap the button, the app crashes with very useless error:

[access] <private>

That's it. Nothing else.

Using break statements, the app seems to crash at "presentViewController".

This is a brand new app and I don't have anything else in the UI other than the grab button.

Also, testing on iOS 9.3, this works fine. Am I missing something which might be changed in iOS 10?

See Question&Answers more detail:os

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

1 Answer

You may need to put the NSPhotoLibraryUsageDescription in your plist. Like

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

Check all the usage descriptions here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...