123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- //
- // uploadImageOrVideoViewController.m
- // 隐私保护
- //
- // Created by xd h on 2023/11/9.
- //
- #import "uploadImageOrVideoViewController.h"
- #import <AssetsLibrary/AssetsLibrary.h>
- #import <AVFoundation/AVFoundation.h>
- #import "AJPhotoListView.h"
- #import "AJPhotoGroupView.h"
- #import "AJPhotoListCell.h"
- #import "uploadFileBottomView.h"
- #import "PhotoPreviewViewController.h"
- #import "TZAssetModel+imageData.h"
- #import "uploadFileRecordViewController.h"
- #import "couldPhoneBaseInfoModel.h"
- #import "fileTransferPathCheckViewController.h"
- #import "ComontAlretViewController.h"
- @interface uploadImageOrVideoViewController ()<AJPhotoGroupViewProtocol,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
- {
- couldPhoneBaseInfoModel *baseInfoModel;
-
- BOOL isNotPhotoPermission;//没有权限
- }
- @property (strong, nonatomic) AJPhotoGroupView *photoGroupView;
- @property (strong, nonatomic) UILabel *MytitleLabel;
- @property (strong, nonatomic) UIImageView *selectTip;
- @property (nonatomic,assign) BOOL isNotAllowed;
- @property (strong, nonatomic) UIView *bgMaskView;
- @property (strong, nonatomic) AJPhotoListView *photoListView;
- @property (strong, nonatomic) NSMutableArray *assets;
- @property (strong, nonatomic) NSIndexPath *lastAccessed;
- @property (strong, nonatomic) uploadFileBottomView *uploadFileBottomV;
- //最多选择项
- //@property (nonatomic, assign) NSInteger maximumNumberOfSelection;
- //最少选择项
- @property (nonatomic, assign) NSInteger minimumNumberOfSelection;
- //是否开启多选
- @property (nonatomic, assign) BOOL multipleSelection;
- @property (nonatomic,assign) BOOL isNotFirstType;
- @end
- @implementation uploadImageOrVideoViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCouldPhoneBaseInfoFun:) name:getCouldPhoneBaseInfoNotification object:nil];
- [self.view setBackgroundColor:HWF5F7FAColor];
-
- [self.toolBar setHidden:YES];
- [self.navigationBar setHidden:YES];
- [self.navBarBGView setHidden:NO];
-
- [self initBaselUIFun];
-
- _isNotAllowed = YES;
- //_maximumNumberOfSelection = 3;
- _minimumNumberOfSelection = 0;
- _multipleSelection = YES;
-
- if(!_selectionFilter)
- {
- _selectionFilter = [NSPredicate predicateWithValue:YES];
- }
- [self checkVideoAccessFun];
-
- [[webRtcManager shareManager] getBaseInfoFun];
- }
- - (void)initBaselUIFun
- {
- [self initNavHeadUIFun];
-
- //列表view
- [self setupPhotoListView];
- [self setupUploadFileBottomView];
- //相册分组
- [self setupGroupView];
- }
- - (void)initNavHeadUIFun
- {
- //title
- UILabel *titleLabel = [[UILabel alloc] init];
- titleLabel.textAlignment = NSTextAlignmentCenter;
- titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
- titleLabel.textColor = [UIColor blackColor];
- titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
- [self.navBarBGView addSubview:titleLabel];
- self.MytitleLabel = titleLabel;
-
- //selectTipImageView
- UIImageView *selectTip = [[UIImageView alloc] init];
- selectTip.image = [UIImage imageNamed:@"upload_image_arrow"];
- selectTip.translatesAutoresizingMaskIntoConstraints = NO;
- [self.navBarBGView addSubview:selectTip];
- self.selectTip = selectTip;
-
- UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- tapBtn.backgroundColor = [UIColor clearColor];
- tapBtn.translatesAutoresizingMaskIntoConstraints = NO;
- [tapBtn addTarget:self action:@selector(selectGroupAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.navBarBGView addSubview:tapBtn];
-
- [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.navBarBGView.mas_centerX);
- make.centerY.mas_equalTo(self.backBtn.mas_centerY);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(30);
- }];
-
- [self setTitleLabelText:@""];
-
- UIButton *rightBut = [[UIButton alloc] init];
- [rightBut setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
- [rightBut setTitle:NSLocalizedString(@"File_upload_cancel_select_all",nil) forState:UIControlStateSelected];
- [rightBut setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
- rightBut.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- [rightBut addTarget:self action:@selector(didClickSelectAllButton:) forControlEvents:UIControlEventTouchUpInside];
-
- [self.navBarBGView addSubview:rightBut];
-
- //多国语言适配
- NSString *languageCode = [NSLocale preferredLanguages][0];
- if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
- {
- rightBut.titleLabel.font = [UIFont systemFontOfSize:13.0];
- }
-
- [rightBut mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-20);
- make.centerY.mas_equalTo(self.backBtn.mas_centerY);
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(30);
- }];
- }
- #pragma mark 设置相册标题
- - (void)setTitleLabelText:(NSString*)title
- {
- self.MytitleLabel.text = title;
-
- CGFloat curWidth = [title boundingRectWithSize:CGSizeMake(SCREEN_W, 30) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18.f]} context:nil].size.width;
-
- curWidth += 20;
- //HLog(@"title w:%f",curWidth);
- [self.MytitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.navBarBGView.mas_centerX).offset(-10);
- make.centerY.mas_equalTo(self.backBtn.mas_centerY);
- make.width.mas_equalTo(curWidth);
- make.height.mas_equalTo(30);
- }];
- //self.MytitleLabel.backgroundColor = [UIColor greenColor];
-
- [self.selectTip mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.MytitleLabel.mas_right).offset(2);
- make.centerY.mas_equalTo(self.backBtn.mas_centerY);
- make.width.mas_equalTo(15);
- make.height.mas_equalTo(15);
- }];
- }
- #pragma mark 点击全选
- - (void)didClickSelectAllButton:(UIButton*)but
- {
- if(!self.assets ||self.assets.count == 0){
- return;
- }
-
- but.selected = !but.selected;
-
- if(but.selected){
- [self.indexPathsForSelectedItems removeAllObjects];
-
- [SVProgressHUD show];
-
- for (int i= 0; i<self.assets.count; i++) {
- TZAssetModel *model = self.assets[i];
-
- if(i == self.assets.count -1){
- [self didSelectModel:model isLastModel:YES];
- }
- else{
- [self didSelectModel:model isLastModel:NO];
- }
- }
-
- // for (TZAssetModel *model in self.assets) {
- // [self didSelectModel:model isLastModel:NO];
- // }
- }
- else{
- for (TZAssetModel *model in self.assets) {
- model.isSelected = NO;
- }
- [self.indexPathsForSelectedItems removeAllObjects];
- }
-
- [self refreshAllDataFun];
- }
- #pragma mark 判断手机相册权限
- - (void)checkVideoAccessFun
- {
- AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
- //判断摄像头状态是否可用
- if(authStatus==AVAuthorizationStatusAuthorized){
- _isNotAllowed = NO;
- }else{
- NSLog(@"未开启相机权限,请前往设置中开启");
- [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
- if (granted){
- self->_isNotAllowed = NO;
- // mainBlock(^{
- //
- // });
- }
- }];
- }
-
- //相册权限
- if (![[TZImageManager manager] authorizationStatusAuthorized]){
- KWeakSelf
- [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
- if(status == PHAuthorizationStatusAuthorized){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.photoGroupView setupGroup];
- [weakSelf delayedSetPhotoGroupViewFrameFun];
- });
- }
- else if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
- mainBlock(^{
- // 用户拒绝授权或设备受限,提示用户去系统设置中开启权限
- [weakSelf requestPhotoLibraryAccessWithAlert];
- });
-
- }
- }];
- }
- }
- /**
- * 照片列表
- */
- - (void)setupPhotoListView {
- AJPhotoListView *collectionView = [[AJPhotoListView alloc] init];
- collectionView.dataSource = self;
- collectionView.delegate = self;
- collectionView.translatesAutoresizingMaskIntoConstraints = NO;
- [self.view insertSubview:collectionView atIndex:0];
- self.photoListView = collectionView;
-
- //空数据引入第三方开源处理
- collectionView.emptyDataSetSource = self;
- collectionView.emptyDataSetDelegate = self;
-
- [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(-(60 + safeArea));
- make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
- }];
- }
- /**
- * 照片列表
- */
- - (void)setupUploadFileBottomView
- {
- uploadFileBottomView *bottomView = [[uploadFileBottomView alloc] init];
- [self.view insertSubview:bottomView atIndex:0];
- self.uploadFileBottomV = bottomView;
-
- [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- make.height.mas_equalTo(60 + safeArea);
- }];
-
- //nas 不需要BaseInfo 相关信息了 修改逻辑
- [self handelAfterGetBaseInfoModelData];
-
- KWeakSelf
- bottomView.didClickUploadFile = ^{
- [weakSelf gotoUploadFileRecordFun];
- };
-
- bottomView.didClickbottomFun = ^{
- [weakSelf gotofileTransferPathCheckVCFun];
- };
- }
- /**
- * 相册
- */
- - (void)setupGroupView {
- AJPhotoGroupView *photoGroupView = [[AJPhotoGroupView alloc] init];
- photoGroupView.my_delegate = self;
- photoGroupView.isPhotoType = _isPhotoType;
- [self.view insertSubview:photoGroupView belowSubview:self.navBarBGView];
- self.photoGroupView = photoGroupView;
- photoGroupView.hidden = YES;
- photoGroupView.translatesAutoresizingMaskIntoConstraints = NO;
-
- [self.photoGroupView setupGroup];
-
- [self delayedSetPhotoGroupViewFrameFun];
- }
- #pragma mark 延时设置photoGroupView frame
- - (void)delayedSetPhotoGroupViewFrameFun
- {
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- NSInteger maxCount = 6;
- if(self.photoGroupView.albumGroups.count < maxCount){
- maxCount = self.photoGroupView.albumGroups.count;
- }
-
- [self.photoGroupView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.height.mas_equalTo(60.0 * maxCount);
- make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
- }];
- });
- }
- #pragma mark - 相册切换
- - (void)selectGroupAction:(UIButton *)sender {
-
- //无权限
- if (self.isNotAllowed) {
- return;
- }
- if (self.photoGroupView.hidden) {
- [self bgMaskView];
- self.bgMaskView.hidden = NO;
- self.photoGroupView.hidden = NO;
- [UIView animateWithDuration:0.3 animations:^{
- CGRect rect = self.photoGroupView.frame;
- rect.origin.y = CGRectGetMaxY(self.navBarBGView.frame);
- self.photoGroupView.frame = rect;
-
- self.selectTip.transform = CGAffineTransformMakeRotation(M_PI);
- }];
- } else {
- [self hidenGroupView];
- }
- }
- - (void)hidenGroupView {
- //[self.bgMaskView removeFromSuperview];
- self.bgMaskView.hidden = YES;
- [UIView animateWithDuration:0.3 animations:^{
- CGRect rect = self.photoGroupView.frame;
- rect.origin.y = -SCREEN_H;
- self.photoGroupView.frame = rect;
-
- self.selectTip.transform = CGAffineTransformIdentity;
- }completion:^(BOOL finished) {
- self.photoGroupView.hidden = YES;
- }];
- }
- #pragma mark - 遮罩背景
- - (UIView *)bgMaskView {
- if (_bgMaskView == nil) {
- UIView *bgMaskView = [[UIView alloc] init];
- bgMaskView.alpha = 0.5;
- bgMaskView.translatesAutoresizingMaskIntoConstraints = NO;
- bgMaskView.backgroundColor = [UIColor blackColor];
- //[self.view insertSubview:bgMaskView aboveSubview:self.photoListView];
- [self.view insertSubview:bgMaskView belowSubview:self.photoGroupView];
-
- bgMaskView.userInteractionEnabled = YES;
- [bgMaskView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgMaskView:)]];
- _bgMaskView = bgMaskView;
-
- [bgMaskView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- make.top.equalTo(self.navBarBGView.mas_bottom).offset(0.f);
- }];
- }
-
- return _bgMaskView;
- }
- - (void)tapBgMaskView:(UITapGestureRecognizer *)sender {
- if (!self.photoGroupView.hidden) {
- [self hidenGroupView];
- }
- }
- #pragma mark - BoPhotoGroupViewProtocol
- - (void)didSelectGroup:(TZAlbumModel *)model {
- [self loadAssets:model];
- [self setTitleLabelText:model.name];
- [self hidenGroupView];
- }
- //加载图片
- - (void)loadAssets:(TZAlbumModel *)model {
- [self.indexPathsForSelectedItems removeAllObjects];
- [self.assets removeAllObjects];
- [[TZImageManager manager] getAssetsFromFetchResult:model.result completion:^(NSArray<TZAssetModel *> *models) {
- self->_assets = [NSMutableArray arrayWithArray:models];
- [self.photoListView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
- [self.photoListView reloadData];
- }];
-
- }
- #pragma mark - uicollectionDelegate
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.assets.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellIdentifer = @"cell";
- AJPhotoListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifer forIndexPath:indexPath];
-
- BOOL isSelected = [self.indexPathsForSelectedItems containsObject:self.assets[indexPath.row]];
- [cell bind:self.assets[indexPath.row] selectionFilter:self.selectionFilter isSelected:isSelected];
-
- KWeakSelf
- cell.didClckSelectBut = ^(BOOL isSelect) {
- [weakSelf handlCellSelectFunBy:indexPath];
- };
-
- return cell;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- return UIEdgeInsetsMake(5, 5, 5, 5);
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat wh = (collectionView.bounds.size.width - 20)/3.0;
- return CGSizeMake(wh, wh);
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
- return 5.0;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- return 5.0;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- NSInteger curRow = indexPath.row;
- PhotoPreviewViewController *vc =[PhotoPreviewViewController new];
- vc.assets = _assets;
- vc.currentIndex = curRow;
- vc.indexPathsForSelectedItems = _indexPathsForSelectedItems;
- //vc.maximumNumberOfSelection = _maximumNumberOfSelection;
- vc.minimumNumberOfSelection = _minimumNumberOfSelection;
- vc.availableStorage = self.uploadFileBottomV.availableStorage;
- vc.isPhotoType = _isPhotoType;
- [self.navigationController pushViewController:vc animated:YES];
-
- KWeakSelf
- vc.changeSelectIndex = ^(NSMutableArray * _Nonnull indexPathsForSelectedItems) {
- [weakSelf refreshDataAndUIFunWith:indexPathsForSelectedItems];
- };
- }
- #pragma mark 空数据
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
-
- NSString *imageName = @"common_no_data_pic";
-
- return [UIImage imageNamed:imageName];
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
- NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
-
- if(isNotPhotoPermission){
- text = NSLocalizedString(@"enable_photo_permission_noData_tip",nil);
- }
-
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
- NSForegroundColorAttributeName: HW999999Color};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- //调整图片位置
- - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
- return -50;
- }
- #pragma mark 从详情页回来 刷新数据和UI
- - (void)refreshDataAndUIFunWith:(NSMutableArray *)indexPathsForSelectedItems
- {
- self.indexPathsForSelectedItems = indexPathsForSelectedItems;
- [self refreshAllDataFun];
- }
- #pragma mark 刷新所有数据
- - (void)refreshAllDataFun
- {
- [self setDataToBottomViewFun];
- [self.photoListView reloadData];
- }
- #pragma mark 处理点击选中相关
- - (void)handlCellSelectFunBy:(NSIndexPath *)indexPath
- {
-
- AJPhotoListCell *cell = (AJPhotoListCell *)[self.photoListView cellForItemAtIndexPath:indexPath];
- TZAssetModel *model = self.assets[indexPath.row];
-
- //超出最大限制
- // if (self.indexPathsForSelectedItems.count >= self.maximumNumberOfSelection ) {
- // return;
- // }
-
- //取消选中
- if ([self.indexPathsForSelectedItems containsObject:model]) {
- [self.indexPathsForSelectedItems removeObject:model];
- model.isSelected = NO;
- [cell isSelected:NO];
-
- [self setDataToBottomViewFun];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
- });
-
- }
- else
- {//选中
- [self didSelectModel:model isLastModel:YES];
- [cell isSelected:YES];
- }
-
- }
- #pragma mark 选中某个cell
- - (void)didSelectModel:(TZAssetModel *)model isLastModel:(BOOL)isLast
- {//选中
- [self.indexPathsForSelectedItems addObject:model];
- model.isSelected = YES;
-
- if(!model.totalBytes)
- {
- [[PHImageManager defaultManager] requestImageDataForAsset:model.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
- // 直接得到最终的 NSData 数据
- if (imageData) {
- //model.imageData = imageData;
- model.totalBytes = [imageData length];
- }
- if(model.type != TZAssetModelMediaTypeVideo){
- [self setDataToBottomViewFun];
- }
-
- if(isLast){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
- });
- }
- }];
-
- if(model.type == TZAssetModelMediaTypeVideo){
-
- PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
- options.version = PHVideoRequestOptionsVersionOriginal;
- [[PHImageManager defaultManager] requestAVAssetForVideo:model.asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
- if ([asset isKindOfClass:[AVURLAsset class]]) {
-
- AVURLAsset* urlAsset = (AVURLAsset*)asset;
-
- //NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
- NSNumber *size;
- [urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
- //NSLog(@"size is %f",[size floatValue]/(1024.0*1024.0));
-
-
- //model.videoData = videoData;
- //model.totalBytes = [videoData length];
- model.totalBytes = size.longLongValue;
- [self setDataToBottomViewFun];
- }
-
- if(isLast){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
- });
- }
-
- }];
- }
- }
- else{
- [self setDataToBottomViewFun];
- if(isLast){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [self.uploadFileBottomV setUploadButtonCanClickFunBy:YES];
- });
- }
- }
- }
- #pragma mark 同步数据到底部
- - (void)setDataToBottomViewFun
- {
- mainBlock(^{
- self.uploadFileBottomV.indexPathsForSelectedItems = self.indexPathsForSelectedItems;
- });
-
- }
- #pragma mark - getter/setter
- - (NSMutableArray *)assets {
- if (!_assets) {
- _assets = [[NSMutableArray alloc] init];
- }
- return _assets;
- }
- - (NSMutableArray *)indexPathsForSelectedItems {
- if (!_indexPathsForSelectedItems) {
- _indexPathsForSelectedItems = [[NSMutableArray alloc] init];
- }
- return _indexPathsForSelectedItems;
- }
- #pragma mark 跳转上传记录
- - (void)gotoUploadFileRecordFun
- {
- uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
- [self.navigationController pushViewController:vc animated:YES];
- vc.isUploadingType = YES;
- [vc gotoUploadFile:_indexPathsForSelectedItems];
-
- if(_isPhotoType){
- //数据埋点
- [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_upload"];
- }
- else{
- //数据埋点
- [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_upload"];
- }
- }
- - (void)getCouldPhoneBaseInfoFun:(NSNotification*)not
- {
- baseInfoModel = [not object];
- //HLog(@"%@",baseInfoModel);
-
- [self handelAfterGetBaseInfoModelData];
- }
- - (void)handelAfterGetBaseInfoModelData
- {
- // if(!baseInfoModel || ![baseInfoModel isKindOfClass:[couldPhoneBaseInfoModel class]]){
- // return;
- // }
-
- NSString * uploadDefaultPath = [HWDataManager getStringWithKey:stringKeyAddSn(Const_photo_upload_default_path)];
-
- if(!uploadDefaultPath || uploadDefaultPath.length == 0){
- [HWDataManager setStringWithKey:stringKeyAddSn(Const_photo_upload_default_path) value:Const_default_upload_path];
- uploadDefaultPath = Const_default_upload_path;
- }
-
- BOOL isExtraFileType = NO;
- BOOL isExtraPathFind = NO;
- if(uploadDefaultPath){
- if(![uploadDefaultPath containsString:@"sdcard/"]){
- isExtraFileType = YES;
- }
- }
-
- if(uploadDefaultPath && ksharedAppDelegate.cloudPhoneExtraFileListMod){
- NSArray*arr = ksharedAppDelegate.cloudPhoneExtraFileListMod.data;
-
- for (cloudPhoneExtraFileModel*model in arr) {
- if([uploadDefaultPath containsString:model.extraPath]){
-
- NSString * availableStorage = @"";
- NSInteger totalSize_k = model.extraAvableSize / 1024;
- if(totalSize_k < 1024){
- availableStorage = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
- }
- else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
- availableStorage = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
-
- }
- else{
- availableStorage = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
- }
-
-
- self.uploadFileBottomV.availableStorage = availableStorage;
- self.uploadFileBottomV.available = model.extraAvableSize;
- isExtraPathFind = YES;
- break;
- }
- }
-
-
- }
-
- if(!isExtraPathFind){
- // self.uploadFileBottomV.availableStorage = baseInfoModel.data.availableStorage;
- // self.uploadFileBottomV.available = baseInfoModel.data.available;
- }
-
- if(isExtraFileType && !isExtraPathFind){
- self.uploadFileBottomV.isExtraFileAndNotFindPathType = YES;
- }
- else{
- self.uploadFileBottomV.isExtraFileAndNotFindPathType = NO;
- }
-
- [self setDataToBottomViewFun];
- }
- - (void)gotofileTransferPathCheckVCFun
- {
- fileTransferPathCheckViewController *vc = [fileTransferPathCheckViewController new];
- vc.curType = 1;
- [self.navigationController pushViewController:vc animated:YES];
-
- KWeakSelf
- vc.didChangeSavePathFun = ^{
- [weakSelf.uploadFileBottomV setSavePathDataFun];
- [weakSelf handelAfterGetBaseInfoModelData];
- };
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
-
- if(!_isNotFirstType){
- [self showUploadTipFun];
-
- //权限访问时 重新拿数据 验证iOS 15.0有效 17.5.1无效 (viewDidAppear 和applicationDidBecomeActive 均不走)
- [self.photoGroupView setupGroup];
- [self delayedSetPhotoGroupViewFrameFun];
- _isNotFirstType = YES;
- }
-
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [SVProgressHUD dismiss];
- }
- - (void)showUploadTipFun
- {
- BOOL didReadUploadTipType = [HWDataManager getBoolWithKey:Const_file_upLoad_need_read];
-
- if(didReadUploadTipType){
- return;
- }
-
-
- //KWeakSelf
- /*弹窗提示恢复出厂*/
- ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:nil
- msg:NSLocalizedString(@"upload_download_need_read_msg",nil)
- imageStr:nil
- cancelTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil)
- okTitle:nil
- isOkBtnHighlight:NO
- didClickOk:^{
-
- } didClickCancel:^{
- [HWDataManager setBoolWithKey:Const_file_upLoad_need_read value:YES];
- }];
-
- nextVC.modalPresentationStyle = UIModalPresentationCustom;
-
- [self presentViewController:nextVC animated:YES completion:^{
- nextVC.view.superview.backgroundColor = [UIColor clearColor];
- }];
-
- }
- #pragma mark 用户拒接授权相册
- - (void)requestPhotoLibraryAccessWithAlert {
-
- isNotPhotoPermission = YES;
- [self.photoListView reloadData];
-
- //KWeakSelf
- /*弹窗提示重启*/
- ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"enable_photo_permission",nil)
- msg:NSLocalizedString(@"enable_photo_permission_tip",nil)
- imageStr:@""
- cancelTitle:NSLocalizedString(@"other_cancel",nil)
- okTitle:NSLocalizedString(@"more_set",nil) isOkBtnHighlight:YES
- didClickOk:^{
- // 打开应用的设置页面
- NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
- }
-
- } didClickCancel:^{
-
- }];
- nextVC.modalPresentationStyle = UIModalPresentationCustom;
- [self presentViewController:nextVC animated:YES completion:^{
- nextVC.view.superview.backgroundColor = [UIColor clearColor];
- }];
-
- }
- @end
|