美文网首页
2021获取相册权限的逻辑

2021获取相册权限的逻辑

作者: 行走在北方 | 来源:发表于2021-03-26 15:24 被阅读0次
     PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];
           if(authStatus == PHAuthorizationStatusNotDetermined) {
               //如果不加这个,就会既有自定义弹窗和系统弹窗
               [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
                   
                   if (status == PHAuthorizationStatusNotDetermined) {
    
                    [self successSaveLibraryNetworkWithIsSaveLibrary:NO];
    
                   } else if (status == PHAuthorizationStatusRestricted) {
                    [self successSaveLibraryNetworkWithIsSaveLibrary:NO];
    
                    } else if (status == PHAuthorizationStatusDenied) {
    
                    [self successSaveLibraryNetworkWithIsSaveLibrary:NO];
    
                    } else {
    
                    }
               }];
    
           }else if (authStatus == PHAuthorizationStatusDenied || authStatus == PHAuthorizationStatusRestricted){
               [self userCustomWindowForNotOpenLibrary];
           }else
           {
               [self successSaveLibraryNetworkWithIsSaveLibrary:YES];
           }
    
    //    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"需要你的图库的权限" preferredStyle:UIAlertControllerStyleAlert];
    //        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    //            //do something
    //        }];
    //        UIAlertAction *requestAction = [UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    //            dispatch_async(dispatch_get_global_queue(0, 0), ^{
    //                [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
    //                    if (status == PHAuthorizationStatusAuthorized) {
    //                        NSLog(@"用户同意授权相册");
    //                    }else {
    //                        NSLog(@"用户拒绝授权相册");
    //                    }
    //                    dispatch_async(dispatch_get_main_queue(), ^{
    //                        //do something
    //                    });
    //                }];
    //
    //            });
    //        }];
    //        [alert addAction:cancelAction];
    //        [alert addAction:requestAction];
    //        [self presentViewController:alert animated:YES completion:nil];
    

    相关文章

      网友评论

          本文标题:2021获取相册权限的逻辑

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