iOS弹出系统相册选择弹窗

直接上代码

复制代码
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self; //设置代理
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [navigationController presentViewController:imagePickerController animated:YES completion:nil];
    }
}

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{}];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //通过key值获取到图片
    self.avatarView.image = image;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{}];
}

注意,弹出相册选择弹窗,不需要申请相册权限, 只有将图片写入系统相册

才需要这个权限,并且,弹出系统相册弹窗的时候,要添加这个判断

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

相关推荐
笑尘pyrotechnic1 天前
LLDB进阶:使用命令行进行检查
ios·objective-c·cocoa·lldb
z***y8621 天前
Swift在iOS中的Xcode
ios·xcode·swift
AirDroid_cn1 天前
iOS 18 后台应用偷跑流量,如何限制?
macos·ios·cocoa
明君879971 天前
Flutter 图纸标注功能的实现:踩坑与架构设计
android·ios
江东小bug王2 天前
深入理解 UINavigationController:生命周期、动画优化与性能调优
ios
Lexiaoyao202 天前
Apple StoreKit 2 开发指南
ios·apple
2501_915106322 天前
iOS App 测试工具全景分析,构建从开发调试到线上监控的多阶段工具链体系
android·测试工具·ios·小程序·uni-app·iphone·webview
Digitally2 天前
如何通过蓝牙将联系人从 iPhone 传输到 Android
android·ios·iphone
90后的晨仔2 天前
2025年11月27日年解决隐私清单导致审核总是提示二进制无效的问题
ios
songgeb3 天前
iOS Audio后台模式下能否执行非Audio逻辑
ios·swift