美文网首页
iOS开发,如何将照片保存到相册

iOS开发,如何将照片保存到相册

作者: 大漠赏花 | 来源:发表于2018-04-02 17:39 被阅读0次

// 保存到本地

- (void)loadImageFinished:(UIImage *)image

{

    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);

}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo

{

    NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);

}

转自:http://www.cocoachina.com/ios/20170629/19676.html?utm_source=itdadao&utm_medium=referral

// 判断相册权限状态

- (IBAction)save {

    // 0.判断状态    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];

    if (status == PHAuthorizationStatusDenied) {

        BSLog(@"用户拒绝当前应用访问相册,我们需要提醒用户打开访问开关");

    }else if (status == PHAuthorizationStatusRestricted){

        BSLog(@"家长控制,不允许访问");

    }else if (status == PHAuthorizationStatusNotDetermined){

        BSLog(@"用户还没有做出选择");

        [self saveImage];

    }else if (status == PHAuthorizationStatusAuthorized){

        BSLog(@"用户允许当前应用访问相册");

        [self saveImage];

    }

}

转自:https://blog.csdn.net/zs18337100488/article/details/51801321

NSPhotoLibraryAddUsageDescription 

打开 Info.plist,点击 + 号,在 Key 中输入:Privacy - Photo Library Additions Usage Description,Type 选择 String,Value 中输入你的提示语。

转自:https://www.jianshu.com/p/bf7de88be6e1

没有权限访问相册时提示用户设置,点击设置跳转到设置界面

// 无权限 引导去开启

        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

        if ([[UIApplication sharedApplication] canOpenURL:url]) {

            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];

        }

openURL相关 :http://www.cocoachina.com/ios/20161021/17824.html

相关文章

网友评论

      本文标题:iOS开发,如何将照片保存到相册

      本文链接:https://www.haomeiwen.com/subject/gspxhftx.html