Commit 7c9dd834c5b2f201eeb76982ec61ae364741f413
1 parent
13a0ab60
提交测试
Showing
3 changed files
with
147 additions
and
29 deletions
Example/CNLiveImagePickerController.xcodeproj/project.pbxproj
| ... | ... | @@ -536,7 +536,7 @@ |
| 536 | 536 | GCC_PREFIX_HEADER = "CNLiveImagePickerController/CNLiveImagePickerController-Prefix.pch"; |
| 537 | 537 | INFOPLIST_FILE = "CNLiveImagePickerController/CNLiveImagePickerController-Info.plist"; |
| 538 | 538 | MODULE_NAME = ExampleApp; |
| 539 | - PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; | |
| 539 | + PRODUCT_BUNDLE_IDENTIFIER = com.cnlive.CNLiveNetAdd.debug; | |
| 540 | 540 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 541 | 541 | SWIFT_VERSION = 4.0; |
| 542 | 542 | WRAPPER_EXTENSION = app; |
| ... | ... | @@ -553,7 +553,7 @@ |
| 553 | 553 | GCC_PREFIX_HEADER = "CNLiveImagePickerController/CNLiveImagePickerController-Prefix.pch"; |
| 554 | 554 | INFOPLIST_FILE = "CNLiveImagePickerController/CNLiveImagePickerController-Info.plist"; |
| 555 | 555 | MODULE_NAME = ExampleApp; |
| 556 | - PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}"; | |
| 556 | + PRODUCT_BUNDLE_IDENTIFIER = com.cnlive.CNLiveNetAdd.debug; | |
| 557 | 557 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 558 | 558 | SWIFT_VERSION = 4.0; |
| 559 | 559 | WRAPPER_EXTENSION = app; | ... | ... |
Example/CNLiveImagePickerController/CNLiveImagePickerController-Info.plist
| ... | ... | @@ -24,35 +24,32 @@ |
| 24 | 24 | <string>1.0</string> |
| 25 | 25 | <key>LSRequiresIPhoneOS</key> |
| 26 | 26 | <true/> |
| 27 | + <key>NSBluetoothAlwaysUsageDescription</key> | |
| 28 | + <string>需要允许开启蓝牙才能对音箱使用配对及配网功能</string> | |
| 29 | + <key>NSBluetoothPeripheralUsageDescription</key> | |
| 30 | + <string>需要允许开启蓝牙才能对音箱使用配对及配网功能</string> | |
| 31 | + <key>NSCameraUsageDescription</key> | |
| 32 | + <string>需要允许开启相机才能在发布生活圈或聊天时使用录制视频和拍照功能</string> | |
| 33 | + <key>NSContactsUsageDescription</key> | |
| 34 | + <string>需要允许访问通讯录才能获取手机联系人中的网家家用户</string> | |
| 35 | + <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> | |
| 36 | + <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 37 | + <key>NSLocationAlwaysUsageDescription</key> | |
| 38 | + <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 39 | + <key>NSLocationWhenInUseUsageDescription</key> | |
| 40 | + <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 41 | + <key>NSMicrophoneUsageDescription</key> | |
| 42 | + <string>需要允许开启麦克风才能使用录制视频和语音等服务</string> | |
| 43 | + <key>NSMotionUsageDescription</key> | |
| 44 | + <string>需要允许访问运动与健身才能在参加线上跑步赛事时记录您的步数信息</string> | |
| 45 | + <key>NSPhotoLibraryAddUsageDescription</key> | |
| 46 | + <string></string> | |
| 47 | + <key>NSPhotoLibraryUsageDescription</key> | |
| 48 | + <string>需要允许打开相册才能访问相册照片和保存照片</string> | |
| 27 | 49 | <key>UILaunchStoryboardName</key> |
| 28 | 50 | <string>LaunchScreen</string> |
| 29 | 51 | <key>UIMainStoryboardFile</key> |
| 30 | 52 | <string>Main</string> |
| 31 | - | |
| 32 | - <key>NSBluetoothAlwaysUsageDescription</key> | |
| 33 | - <string>需要允许开启蓝牙才能对音箱使用配对及配网功能</string> | |
| 34 | - <key>NSBluetoothPeripheralUsageDescription</key> | |
| 35 | - <string>需要允许开启蓝牙才能对音箱使用配对及配网功能</string> | |
| 36 | - <key>NSCameraUsageDescription</key> | |
| 37 | - <string>需要允许开启相机才能在发布生活圈或聊天时使用录制视频和拍照功能</string> | |
| 38 | - <key>NSContactsUsageDescription</key> | |
| 39 | - <string>需要允许访问通讯录才能获取手机联系人中的网家家用户</string> | |
| 40 | - <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> | |
| 41 | - <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 42 | - <key>NSLocationAlwaysUsageDescription</key> | |
| 43 | - <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 44 | - <key>NSLocationWhenInUseUsageDescription</key> | |
| 45 | - <string>需要允许使用您的位置信息才能获取您所在的城市</string> | |
| 46 | - <key>NSMicrophoneUsageDescription</key> | |
| 47 | - <string>需要允许开启麦克风才能使用录制视频和语音等服务</string> | |
| 48 | - <key>NSMotionUsageDescription</key> | |
| 49 | - <string>需要允许访问运动与健身才能在参加线上跑步赛事时记录您的步数信息</string> | |
| 50 | - | |
| 51 | - <key>NSPhotoLibraryAddUsageDescription</key> | |
| 52 | - <string></string> | |
| 53 | - <key>NSPhotoLibraryUsageDescription</key> | |
| 54 | - <string>需要允许打开相册才能访问相册照片和保存照片</string> | |
| 55 | - | |
| 56 | 53 | <key>UIRequiredDeviceCapabilities</key> |
| 57 | 54 | <array> |
| 58 | 55 | <string>armv7</string> | ... | ... |
Example/CNLiveImagePickerController/CNLiveViewController.m
| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | |
| 9 | 9 | #import "CNLiveViewController.h" |
| 10 | 10 | #import "CNImagePickerManager.h" |
| 11 | +#import <CNLiveUploadManager/CNLiveUploadManager.h> | |
| 11 | 12 | |
| 12 | 13 | @interface CNLiveViewController ()<TZImagePickerControllerDelegate> |
| 13 | 14 | |
| ... | ... | @@ -32,9 +33,129 @@ |
| 32 | 33 | |
| 33 | 34 | - (void)buttonAction:(UIButton *)sender { |
| 34 | 35 | |
| 35 | - [CNImagePickerManager ImagePickerWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES isSelectOriginalPhoto:nil selectedAssets:nil enterType:CNImagePickerEnterTypeFriendsCircle pickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 36 | +// [CNImagePickerManager ImagePickerWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES isSelectOriginalPhoto:nil selectedAssets:nil enterType:CNImagePickerEnterTypeFriendsCircle pickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 37 | +// | |
| 38 | +// }]; | |
| 39 | + | |
| 40 | + CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc]initWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES]; | |
| 41 | + [imagePickerVc configTZImagePicker];//配置 | |
| 42 | + imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; | |
| 43 | + imagePickerVc.isSelectOriginalPhoto = NO;//是否选择原图 | |
| 44 | + // 1.设置目前已经选中的图片数组 | |
| 45 | + imagePickerVc.selectedAssets = nil; // 目前已经选中的图片数组 | |
| 46 | + // 发布时长限制 | |
| 47 | + imagePickerVc.maxEditVideoTime = kChat_limit_video_length; | |
| 48 | + imagePickerVc.maxVideoDuration = kChat_limit_video_length; | |
| 49 | + imagePickerVc.conversationId = @"defult"; | |
| 50 | + imagePickerVc.timeout = 300; | |
| 51 | + imagePickerVc.isExportVideo = YES;//允许导出 | |
| 52 | + /// 5. Single selection mode, valid when maxImagesCount = 1 | |
| 53 | + /// 5. 单选模式,maxImagesCount为1时才生效 | |
| 54 | + // 设置竖屏下的裁剪尺寸 | |
| 55 | + NSInteger left = 30; | |
| 56 | + NSInteger widthHeight = self.view.width - 2 * left; | |
| 57 | + NSInteger top = (self.view.height - widthHeight) / 2; | |
| 58 | + imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight); | |
| 59 | + | |
| 60 | + // You can get the photos by block, the same as by delegate. | |
| 61 | + // 你可以通过block或者代理,来得到用户选择的照片. | |
| 62 | + __weak typeof(self) weakSelf = self; | |
| 63 | + [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 64 | + | |
| 65 | + }]; | |
| 66 | + [imagePickerVc setImagePickerControllerDidCancelHandle:^{ | |
| 67 | + | |
| 68 | + | |
| 69 | + }]; | |
| 70 | + [imagePickerVc setDidNewFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray<TZAssetModel *> *models, NSArray *assets, BOOL isSelectOriginalPhoto) { | |
| 71 | + NSLog(@"输出models = %@",models); | |
| 72 | + // | |
| 73 | + NSMutableArray *operationArray = [NSMutableArray new]; | |
| 74 | + for (int i = 0; i < photos.count;i++ ) { | |
| 75 | + | |
| 76 | + NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ | |
| 77 | + UIImage *img = photos[i]; | |
| 78 | + TZAssetModel *model = models[i]; | |
| 79 | + | |
| 80 | + //进行图片视频压缩(LXG) | |
| 81 | + if (model.type == TZAssetModelMediaTypeVideo) | |
| 82 | + {//视频 | |
| 83 | + NSError *err = nil; | |
| 84 | + if (!model.exportURL) { | |
| 85 | + NSLog(@"///////导出失败"); | |
| 86 | + return; | |
| 87 | + } | |
| 88 | + NSData* data = [NSData dataWithContentsOfURL:model.exportURL options:NSDataReadingMappedIfSafe error:&err]; | |
| 89 | + | |
| 90 | + NSLog(@"已经导出视频"); | |
| 91 | + | |
| 92 | + | |
| 93 | + }else | |
| 94 | + { | |
| 95 | + | |
| 96 | + if ([CNLiveBusinessTools isGif:assets[i]]) { | |
| 97 | + img.isGif = @"1"; | |
| 98 | + PHImageManager *imageManager = [PHImageManager defaultManager]; | |
| 99 | + PHImageRequestOptions *options = [PHImageRequestOptions new]; | |
| 100 | + options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat; | |
| 101 | + options.resizeMode = PHImageRequestOptionsResizeModeNone; | |
| 102 | + // options.networkAccessAllowed = YES; | |
| 103 | + [imageManager requestImageDataForAsset:assets[i] options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { | |
| 104 | + img.imageData = imageData; | |
| 105 | + if (imageData.length > kChat_limit_photo) { | |
| 106 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 107 | + | |
| 108 | + NSLog(@"图片过大"); | |
| 109 | + }); | |
| 110 | + } | |
| 111 | + else{ | |
| 112 | + NSLog(@"发送图片"); | |
| 113 | + } | |
| 114 | + | |
| 115 | + }]; | |
| 116 | + } | |
| 117 | + else | |
| 118 | + { | |
| 119 | + | |
| 120 | + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
| 121 | + // 进行图片压缩(LXG) | |
| 122 | + NSData *zipData = nil; | |
| 123 | + if (isSelectOriginalPhoto) {//是否原图 | |
| 124 | + zipData = [UIImage zipNSDataWithImage:img isOriginal:YES];//原图压缩 | |
| 125 | + | |
| 126 | + }else{ | |
| 127 | + //zipNSDataWithImage | |
| 128 | + zipData = [UIImage zipNSDataWithImage:img];//非原图压缩1028 | |
| 129 | + } | |
| 130 | + | |
| 131 | + if (zipData.length > kChat_limit_photo) {//压缩后大于20M | |
| 132 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 133 | + if (isSelectOriginalPhoto) { | |
| 134 | + NSLog(@"发送的原图过大"); | |
| 135 | + }else{ | |
| 136 | + NSLog(@"发送的图过大"); | |
| 137 | + } | |
| 138 | + }); | |
| 139 | + } | |
| 140 | + else{ | |
| 141 | + NSLog(@"发送图片"); | |
| 142 | + } | |
| 143 | + | |
| 144 | + }); | |
| 145 | + | |
| 146 | + } | |
| 147 | + | |
| 148 | + } | |
| 149 | + }]; | |
| 150 | + | |
| 151 | + [operationArray addObject:operation]; | |
| 152 | + | |
| 153 | + } | |
| 154 | + | |
| 155 | + | |
| 156 | + }]; | |
| 36 | 157 | |
| 37 | - }]; | |
| 158 | + [self presentViewController:imagePickerVc animated:YES completion:nil]; | |
| 38 | 159 | |
| 39 | 160 | } |
| 40 | 161 | ... | ... |