Commit afd7749ba04e50405683956534d6d6fbc96d27b9
1 parent
3bf2be22
修改Demo
Showing
3 changed files
with
145 additions
and
74 deletions
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo.xcodeproj/project.pbxproj
| @@ -16,7 +16,6 @@ | @@ -16,7 +16,6 @@ | ||
| 16 | 81B9CBA11F54204F009594FB /* CNLiveUploadController.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */; }; | 16 | 81B9CBA11F54204F009594FB /* CNLiveUploadController.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */; }; |
| 17 | 81B9CBA81F54207B009594FB /* KS3YunSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */; }; | 17 | 81B9CBA81F54207B009594FB /* KS3YunSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */; }; |
| 18 | 81B9CBA91F54207B009594FB /* KS3YunSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; | 18 | 81B9CBA91F54207B009594FB /* KS3YunSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; |
| 19 | - 81B9CBAE1F5421C6009594FB /* 7.6M.mov in Resources */ = {isa = PBXBuildFile; fileRef = 81B9CBAD1F5421C6009594FB /* 7.6M.mov */; }; | ||
| 20 | D21D75D51FE0C9C700658839 /* cnlive.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = D21D75D41FE0C9C600658839 /* cnlive.mp4 */; }; | 19 | D21D75D51FE0C9C700658839 /* cnlive.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = D21D75D41FE0C9C600658839 /* cnlive.mp4 */; }; |
| 21 | D2DD1B311FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */; }; | 20 | D2DD1B311FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */; }; |
| 22 | D2DD1B331FDFDA6F001DFDD1 /* CNLiveUploadYunSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; | 21 | D2DD1B331FDFDA6F001DFDD1 /* CNLiveUploadYunSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; |
| @@ -51,7 +50,6 @@ | @@ -51,7 +50,6 @@ | ||
| 51 | 81B9CB9F1F54204F009594FB /* CNLiveUploadController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLiveUploadController.h; sourceTree = "<group>"; }; | 50 | 81B9CB9F1F54204F009594FB /* CNLiveUploadController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLiveUploadController.h; sourceTree = "<group>"; }; |
| 52 | 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveUploadController.m; sourceTree = "<group>"; }; | 51 | 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveUploadController.m; sourceTree = "<group>"; }; |
| 53 | 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = KS3YunSDK.framework; sourceTree = "<group>"; }; | 52 | 81B9CBA31F54205E009594FB /* KS3YunSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = KS3YunSDK.framework; sourceTree = "<group>"; }; |
| 54 | - 81B9CBAD1F5421C6009594FB /* 7.6M.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = 7.6M.mov; sourceTree = "<group>"; }; | ||
| 55 | D21D75D41FE0C9C600658839 /* cnlive.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = cnlive.mp4; sourceTree = "<group>"; }; | 53 | D21D75D41FE0C9C600658839 /* cnlive.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = cnlive.mp4; sourceTree = "<group>"; }; |
| 56 | D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CNLiveUploadYunSDK.framework; sourceTree = "<group>"; }; | 54 | D2DD1B301FDFDA6C001DFDD1 /* CNLiveUploadYunSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CNLiveUploadYunSDK.framework; sourceTree = "<group>"; }; |
| 57 | /* End PBXFileReference section */ | 55 | /* End PBXFileReference section */ |
| @@ -96,7 +94,6 @@ | @@ -96,7 +94,6 @@ | ||
| 96 | 81B9CB8F1F542006009594FB /* ViewController.m */, | 94 | 81B9CB8F1F542006009594FB /* ViewController.m */, |
| 97 | 81B9CB9F1F54204F009594FB /* CNLiveUploadController.h */, | 95 | 81B9CB9F1F54204F009594FB /* CNLiveUploadController.h */, |
| 98 | 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */, | 96 | 81B9CBA01F54204F009594FB /* CNLiveUploadController.m */, |
| 99 | - 81B9CBAD1F5421C6009594FB /* 7.6M.mov */, | ||
| 100 | D21D75D41FE0C9C600658839 /* cnlive.mp4 */, | 97 | D21D75D41FE0C9C600658839 /* cnlive.mp4 */, |
| 101 | 81B9CB911F542006009594FB /* Main.storyboard */, | 98 | 81B9CB911F542006009594FB /* Main.storyboard */, |
| 102 | 81B9CB941F542006009594FB /* Assets.xcassets */, | 99 | 81B9CB941F542006009594FB /* Assets.xcassets */, |
| @@ -142,7 +139,7 @@ | @@ -142,7 +139,7 @@ | ||
| 142 | 81B9CB7D1F542006009594FB /* Project object */ = { | 139 | 81B9CB7D1F542006009594FB /* Project object */ = { |
| 143 | isa = PBXProject; | 140 | isa = PBXProject; |
| 144 | attributes = { | 141 | attributes = { |
| 145 | - LastUpgradeCheck = 0830; | 142 | + LastUpgradeCheck = 0920; |
| 146 | ORGANIZATIONNAME = zhulin; | 143 | ORGANIZATIONNAME = zhulin; |
| 147 | TargetAttributes = { | 144 | TargetAttributes = { |
| 148 | 81B9CB841F542006009594FB = { | 145 | 81B9CB841F542006009594FB = { |
| @@ -175,7 +172,6 @@ | @@ -175,7 +172,6 @@ | ||
| 175 | isa = PBXResourcesBuildPhase; | 172 | isa = PBXResourcesBuildPhase; |
| 176 | buildActionMask = 2147483647; | 173 | buildActionMask = 2147483647; |
| 177 | files = ( | 174 | files = ( |
| 178 | - 81B9CBAE1F5421C6009594FB /* 7.6M.mov in Resources */, | ||
| 179 | D21D75D51FE0C9C700658839 /* cnlive.mp4 in Resources */, | 175 | D21D75D51FE0C9C700658839 /* cnlive.mp4 in Resources */, |
| 180 | 81B9CB981F542006009594FB /* LaunchScreen.storyboard in Resources */, | 176 | 81B9CB981F542006009594FB /* LaunchScreen.storyboard in Resources */, |
| 181 | 81B9CB951F542006009594FB /* Assets.xcassets in Resources */, | 177 | 81B9CB951F542006009594FB /* Assets.xcassets in Resources */, |
| @@ -229,7 +225,9 @@ | @@ -229,7 +225,9 @@ | ||
| 229 | CLANG_CXX_LIBRARY = "libc++"; | 225 | CLANG_CXX_LIBRARY = "libc++"; |
| 230 | CLANG_ENABLE_MODULES = YES; | 226 | CLANG_ENABLE_MODULES = YES; |
| 231 | CLANG_ENABLE_OBJC_ARC = YES; | 227 | CLANG_ENABLE_OBJC_ARC = YES; |
| 228 | + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; | ||
| 232 | CLANG_WARN_BOOL_CONVERSION = YES; | 229 | CLANG_WARN_BOOL_CONVERSION = YES; |
| 230 | + CLANG_WARN_COMMA = YES; | ||
| 233 | CLANG_WARN_CONSTANT_CONVERSION = YES; | 231 | CLANG_WARN_CONSTANT_CONVERSION = YES; |
| 234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | 232 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; |
| 235 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | 233 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; |
| @@ -237,7 +235,11 @@ | @@ -237,7 +235,11 @@ | ||
| 237 | CLANG_WARN_ENUM_CONVERSION = YES; | 235 | CLANG_WARN_ENUM_CONVERSION = YES; |
| 238 | CLANG_WARN_INFINITE_RECURSION = YES; | 236 | CLANG_WARN_INFINITE_RECURSION = YES; |
| 239 | CLANG_WARN_INT_CONVERSION = YES; | 237 | CLANG_WARN_INT_CONVERSION = YES; |
| 238 | + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; | ||
| 239 | + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | ||
| 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; |
| 241 | + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | ||
| 242 | + CLANG_WARN_STRICT_PROTOTYPES = YES; | ||
| 241 | CLANG_WARN_SUSPICIOUS_MOVE = YES; | 243 | CLANG_WARN_SUSPICIOUS_MOVE = YES; |
| 242 | CLANG_WARN_UNREACHABLE_CODE = YES; | 244 | CLANG_WARN_UNREACHABLE_CODE = YES; |
| 243 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | 245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; |
| @@ -278,7 +280,9 @@ | @@ -278,7 +280,9 @@ | ||
| 278 | CLANG_CXX_LIBRARY = "libc++"; | 280 | CLANG_CXX_LIBRARY = "libc++"; |
| 279 | CLANG_ENABLE_MODULES = YES; | 281 | CLANG_ENABLE_MODULES = YES; |
| 280 | CLANG_ENABLE_OBJC_ARC = YES; | 282 | CLANG_ENABLE_OBJC_ARC = YES; |
| 283 | + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; | ||
| 281 | CLANG_WARN_BOOL_CONVERSION = YES; | 284 | CLANG_WARN_BOOL_CONVERSION = YES; |
| 285 | + CLANG_WARN_COMMA = YES; | ||
| 282 | CLANG_WARN_CONSTANT_CONVERSION = YES; | 286 | CLANG_WARN_CONSTANT_CONVERSION = YES; |
| 283 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | 287 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; |
| 284 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | 288 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; |
| @@ -286,7 +290,11 @@ | @@ -286,7 +290,11 @@ | ||
| 286 | CLANG_WARN_ENUM_CONVERSION = YES; | 290 | CLANG_WARN_ENUM_CONVERSION = YES; |
| 287 | CLANG_WARN_INFINITE_RECURSION = YES; | 291 | CLANG_WARN_INFINITE_RECURSION = YES; |
| 288 | CLANG_WARN_INT_CONVERSION = YES; | 292 | CLANG_WARN_INT_CONVERSION = YES; |
| 293 | + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; | ||
| 294 | + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | ||
| 289 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | 295 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; |
| 296 | + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | ||
| 297 | + CLANG_WARN_STRICT_PROTOTYPES = YES; | ||
| 290 | CLANG_WARN_SUSPICIOUS_MOVE = YES; | 298 | CLANG_WARN_SUSPICIOUS_MOVE = YES; |
| 291 | CLANG_WARN_UNREACHABLE_CODE = YES; | 299 | CLANG_WARN_UNREACHABLE_CODE = YES; |
| 292 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | 300 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; |
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo/7.6M.mov deleted
100755 → 0
No preview for this file type
CNLiveUploadYunSDKDemo/CNLiveUploadYunSDKDemo/CNLiveUploadController.m
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | #import "CNLiveUploadController.h" | 9 | #import "CNLiveUploadController.h" |
| 10 | #import <AssetsLibrary/AssetsLibrary.h> | 10 | #import <AssetsLibrary/AssetsLibrary.h> |
| 11 | #import <CNLiveUploadYunSDK/CNLiveUploadYunSDK.h> | 11 | #import <CNLiveUploadYunSDK/CNLiveUploadYunSDK.h> |
| 12 | +#import <MobileCoreServices/MobileCoreServices.h> | ||
| 12 | 13 | ||
| 13 | #define mScreenWidth ([UIScreen mainScreen].bounds.size.width) | 14 | #define mScreenWidth ([UIScreen mainScreen].bounds.size.width) |
| 14 | #define mScreenHeight ([UIScreen mainScreen].bounds.size.height) | 15 | #define mScreenHeight ([UIScreen mainScreen].bounds.size.height) |
| @@ -19,11 +20,14 @@ | @@ -19,11 +20,14 @@ | ||
| 19 | #define keyUploadPartNum @"partNum" //需要app本地存储已经传成功的块号,demo为了演示,用NSUserDefaults存储,app可用数据库等 | 20 | #define keyUploadPartNum @"partNum" //需要app本地存储已经传成功的块号,demo为了演示,用NSUserDefaults存储,app可用数据库等 |
| 20 | #define keyUploadId @"uploadId" //需要app本地存储已经初始化成功的uploadId,用于断点续传,demo为了演示,用NSUserDefaults存储,app可用数据库等 | 21 | #define keyUploadId @"uploadId" //需要app本地存储已经初始化成功的uploadId,用于断点续传,demo为了演示,用NSUserDefaults存储,app可用数据库等 |
| 21 | 22 | ||
| 22 | -@interface CNLiveUploadController ()<UITableViewDelegate,UITableViewDataSource,KingSoftServiceRequestDelegate> | 23 | +@interface CNLiveUploadController ()<UITableViewDelegate,UITableViewDataSource,KingSoftServiceRequestDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> |
| 23 | { | 24 | { |
| 25 | + NSURL *_imageAssetUrl;//相册文件URL | ||
| 26 | + CNLiveUploadType _uploadType;//选择文件方式type | ||
| 24 | NSString *_bucketKey;//SP上传时用到的bucket里文件的路径(包含扩展名) | 27 | NSString *_bucketKey;//SP上传时用到的bucket里文件的路径(包含扩展名) |
| 25 | } | 28 | } |
| 26 | @property (nonatomic ,strong) UITableView * tableView;//列表 | 29 | @property (nonatomic ,strong) UITableView * tableView;//列表 |
| 30 | +@property (nonatomic ,strong) UIButton * styleBtn;//上传方式按钮 | ||
| 27 | 31 | ||
| 28 | @property (assign, nonatomic) long long fileSize;//文件大小 | 32 | @property (assign, nonatomic) long long fileSize;//文件大小 |
| 29 | @property (assign, nonatomic) NSInteger partSize;//单块大小 | 33 | @property (assign, nonatomic) NSInteger partSize;//单块大小 |
| @@ -42,78 +46,49 @@ | @@ -42,78 +46,49 @@ | ||
| 42 | // Do any additional setup after loading the view. | 46 | // Do any additional setup after loading the view. |
| 43 | self.view.backgroundColor = [UIColor whiteColor]; | 47 | self.view.backgroundColor = [UIColor whiteColor]; |
| 44 | self.navigationItem.title = @"上传"; | 48 | self.navigationItem.title = @"上传"; |
| 45 | - _arrItems = [NSArray arrayWithObjects:@"Multipart Upload", @"Abort Upload", @"Put Object", nil]; | 49 | + _arrItems = [NSArray arrayWithObjects:@"Multipart Upload", @"Abort Multipart Upload", @"Put Single Object", nil]; |
| 46 | 50 | ||
| 47 | - self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; | 51 | + self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMinY(self.view.frame), mScreenWidth, mScreenHeight-100)]; |
| 48 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CNLiveUpload"]; | 52 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CNLiveUpload"]; |
| 49 | [self.view addSubview:self.tableView]; | 53 | [self.view addSubview:self.tableView]; |
| 50 | self.tableView.delegate = self; | 54 | self.tableView.delegate = self; |
| 51 | self.tableView.dataSource = self; | 55 | self.tableView.dataSource = self; |
| 52 | 56 | ||
| 57 | + [self.view addSubview:self.styleBtn]; | ||
| 53 | [self getBucketKeyFromServer]; | 58 | [self getBucketKeyFromServer]; |
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | - | ||
| 57 | /** | 61 | /** |
| 58 | 从服务器获取BucketKey,BucketKey为文件路径 | 62 | 从服务器获取BucketKey,BucketKey为文件路径 |
| 59 | */ | 63 | */ |
| 60 | -- (void)getBucketKeyFromServer | 64 | +- (NSString *)getBucketKeyFromServer |
| 61 | { | 65 | { |
| 62 | -#warning 此处建议从server获取 上传文件对应的bucketKey(文件路径包含扩展名) | 66 | +#warning 此处建议从server获取,为每一个上传的文件分配唯一的bucketKey,上传文件对应的bucketKey(文件路径包含扩展名). 例:完整bucketKey为@"cnlive-test/cnlive.mp4",可由服务器返回@"cnlive-test/cnlive",扩展名@".mp4"由开发者拼接,组成完整的bucketKey |
| 63 | #warning Demo为了演示 bucketKey用固定值 | 67 | #warning Demo为了演示 bucketKey用固定值 |
| 64 | - _bucketKey = @"cnlive-test/cnlive.mp4"; | 68 | + _bucketKey = @"cnlive-uploadtest/cnlive.mp4";//本地工程文件 |
| 69 | + return _bucketKey; | ||
| 65 | } | 70 | } |
| 66 | 71 | ||
| 67 | -#pragma mark 相册方法 | ||
| 68 | -/* | ||
| 69 | - 这里,枚举模拟器相册所有的视频,模拟器只有一个只能获得开头传入的7.6M视频, | ||
| 70 | - 具体工程使用时根据具体逻辑,获取到Alasset即可 | ||
| 71 | - KS3Client 方法: | ||
| 72 | - - (NSData *)getUploadPartDataWithPartNum:(NSInteger)partNum | ||
| 73 | - partLength:(NSInteger)partlength | ||
| 74 | - alassetURL:(NSURL *)alassetURL; | ||
| 75 | - | ||
| 76 | - - (NSData *)getUploadPartDataWithPartNum:(NSInteger)partNum | ||
| 77 | - partLength:(NSInteger)partlength | ||
| 78 | - Alasset:(ALAsset *)assets; | ||
| 79 | - | ||
| 80 | - - (ALAsset *)getAlassetFromAlassetURL:(NSURL *)alassetURL; | ||
| 81 | - | ||
| 82 | - */ | ||
| 83 | -- (ALAsset *)getAlasset | 72 | +- (NSString *)bucketKey |
| 84 | { | 73 | { |
| 85 | - ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init]; | ||
| 86 | - __block ALAsset *assets ; | ||
| 87 | - dispatch_semaphore_t sem= dispatch_semaphore_create(0); | ||
| 88 | - dispatch_queue_t concurrentQueue = dispatch_queue_create("my.concurrent.queue", DISPATCH_QUEUE_SERIAL); | ||
| 89 | - dispatch_async(concurrentQueue, ^{ | ||
| 90 | - [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { | ||
| 91 | - if (group) { | ||
| 92 | - [group setAssetsFilter:[ALAssetsFilter allVideos]]; | ||
| 93 | - [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { | ||
| 94 | - if (result) { | ||
| 95 | - assets = result; | ||
| 96 | - NSLog(@"url = %@",assets.defaultRepresentation.url); | ||
| 97 | - dispatch_semaphore_signal(sem); | ||
| 98 | - return ; | ||
| 99 | - } | ||
| 100 | - }]; | ||
| 101 | - dispatch_semaphore_signal(sem); | ||
| 102 | - }else | ||
| 103 | - { | ||
| 104 | - // NSLog(@"group为空,枚举失败"); | ||
| 105 | - } | ||
| 106 | - dispatch_semaphore_signal(sem); | ||
| 107 | - } failureBlock:^(NSError *error) { | ||
| 108 | - | ||
| 109 | - NSLog(@"请到设置->隐私->照片中开启,访问照片库的权限"); | ||
| 110 | - dispatch_semaphore_signal(sem); | ||
| 111 | - }]; | ||
| 112 | - }); | ||
| 113 | - | ||
| 114 | - dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); | ||
| 115 | - | ||
| 116 | - return assets; | 74 | + switch (_uploadType) { |
| 75 | + case kCNLiveUploadNormal: | ||
| 76 | + {//本地文件 | ||
| 77 | + _bucketKey = [self getBucketKeyFromServer]; | ||
| 78 | + } | ||
| 79 | + break; | ||
| 80 | + case kCNLiveUploadAlasset: | ||
| 81 | + {//相册选取的文件,重新拼接扩展名 | ||
| 82 | + NSString *bucketKeyUnExt = [[self getBucketKeyFromServer] substringToIndex:_bucketKey.length - 4]; | ||
| 83 | + NSArray *arr = [_imageAssetUrl.absoluteString componentsSeparatedByString:@"ext="]; | ||
| 84 | + NSString *ext = arr[1]; | ||
| 85 | + _bucketKey = [NSString stringWithFormat:@"%@.%@",bucketKeyUnExt,ext]; | ||
| 86 | + } | ||
| 87 | + break; | ||
| 88 | + default: | ||
| 89 | + break; | ||
| 90 | + } | ||
| 91 | + return _bucketKey; | ||
| 117 | } | 92 | } |
| 118 | 93 | ||
| 119 | #pragma mark 上传方法 | 94 | #pragma mark 上传方法 |
| @@ -137,7 +112,8 @@ | @@ -137,7 +112,8 @@ | ||
| 137 | - (void)beginMultipartUpload | 112 | - (void)beginMultipartUpload |
| 138 | { | 113 | { |
| 139 | [CNLiveUpload initCNLiveUploadWithSuccess:^{ | 114 | [CNLiveUpload initCNLiveUploadWithSuccess:^{ |
| 140 | - NSString *strKey = _bucketKey; | 115 | + |
| 116 | + NSString *strKey = [self bucketKey]; | ||
| 141 | _partSize = 5; // 文件大于5M为最小5M一块 | 117 | _partSize = 5; // 文件大于5M为最小5M一块 |
| 142 | 118 | ||
| 143 | CNLiveAccessControlList *acl = [[CNLiveAccessControlList alloc] init]; | 119 | CNLiveAccessControlList *acl = [[CNLiveAccessControlList alloc] init]; |
| @@ -160,12 +136,12 @@ | @@ -160,12 +136,12 @@ | ||
| 160 | } | 136 | } |
| 161 | 137 | ||
| 162 | //选择相册还是普通方式 | 138 | //选择相册还是普通方式 |
| 163 | - _muilt.uploadType = kCNLiveUploadNormal; | 139 | + _muilt.uploadType = _uploadType; |
| 164 | 140 | ||
| 165 | //根据文件路径不一样,有如下两种上传 | 141 | //根据文件路径不一样,有如下两种上传 |
| 166 | if (_muilt.uploadType == kCNLiveUploadNormal) { //如果是沙盒或者工程里的文件 | 142 | if (_muilt.uploadType == kCNLiveUploadNormal) { //如果是沙盒或者工程里的文件 |
| 167 | //工程里,沙盒里,是沙盒路径 | 143 | //工程里,沙盒里,是沙盒路径 |
| 168 | - NSString *strFilePath = [[NSBundle mainBundle] pathForResource:@"7.6M" ofType:@"mov"]; | 144 | + NSString *strFilePath = [[NSBundle mainBundle] pathForResource:@"cnlive" ofType:@"mp4"]; |
| 169 | _fileHandle = [NSFileHandle fileHandleForReadingAtPath:strFilePath]; | 145 | _fileHandle = [NSFileHandle fileHandleForReadingAtPath:strFilePath]; |
| 170 | _fileSize = [_fileHandle availableData].length; | 146 | _fileSize = [_fileHandle availableData].length; |
| 171 | if (_fileSize <= 0) { | 147 | if (_fileSize <= 0) { |
| @@ -182,7 +158,9 @@ | @@ -182,7 +158,9 @@ | ||
| 182 | }else | 158 | }else |
| 183 | { | 159 | { |
| 184 | //如果是相册里的,从这传 | 160 | //如果是相册里的,从这传 |
| 185 | - ALAssetRepresentation *assetD = [self getAlasset].defaultRepresentation; | 161 | + ALAsset *assets = [[CNLiveClient initialize] getAlassetFromAlassetURL:_imageAssetUrl]; |
| 162 | + ALAssetRepresentation *assetD = assets.defaultRepresentation; | ||
| 163 | + | ||
| 186 | _fileSize = assetD.size; | 164 | _fileSize = assetD.size; |
| 187 | if (_fileSize <= 0) { | 165 | if (_fileSize <= 0) { |
| 188 | NSLog(@"####This file is not exist!####"); | 166 | NSLog(@"####This file is not exist!####"); |
| @@ -248,7 +226,8 @@ | @@ -248,7 +226,8 @@ | ||
| 248 | NSData *data = nil; | 226 | NSData *data = nil; |
| 249 | if (_muilt.uploadType == kCNLiveUploadAlasset) { | 227 | if (_muilt.uploadType == kCNLiveUploadAlasset) { |
| 250 | //相册信息 | 228 | //相册信息 |
| 251 | - data = [[CNLiveClient initialize] getUploadPartDataWithPartNum:partNumber partLength:FileBlockSize Alasset:[self getAlasset]]; | 229 | + ALAsset *assets = [[CNLiveClient initialize] getAlassetFromAlassetURL:_imageAssetUrl]; |
| 230 | + data = [[CNLiveClient initialize] getUploadPartDataWithPartNum:partNumber partLength:FileBlockSize Alasset:assets]; | ||
| 252 | }else | 231 | }else |
| 253 | { | 232 | { |
| 254 | //沙盒路径 | 233 | //沙盒路径 |
| @@ -310,7 +289,7 @@ | @@ -310,7 +289,7 @@ | ||
| 310 | NSLog(@"error: %@", response.error.description); | 289 | NSLog(@"error: %@", response.error.description); |
| 311 | } | 290 | } |
| 312 | } failure:^(NSDictionary *error) { | 291 | } failure:^(NSDictionary *error) { |
| 313 | - NSLog(@"error %@",error); | 292 | + |
| 314 | }]; | 293 | }]; |
| 315 | } | 294 | } |
| 316 | 295 | ||
| @@ -319,15 +298,16 @@ | @@ -319,15 +298,16 @@ | ||
| 319 | - (void)beginSingleUpload:(NSInteger) row | 298 | - (void)beginSingleUpload:(NSInteger) row |
| 320 | { | 299 | { |
| 321 | [CNLiveUpload initCNLiveUploadWithSuccess:^{ | 300 | [CNLiveUpload initCNLiveUploadWithSuccess:^{ |
| 301 | + | ||
| 322 | CNLiveAccessControlList *ControlList = [[CNLiveAccessControlList alloc] init]; | 302 | CNLiveAccessControlList *ControlList = [[CNLiveAccessControlList alloc] init]; |
| 323 | [ControlList setContronAccess:CNLiveYun_Permission_Public_Read_Write]; | 303 | [ControlList setContronAccess:CNLiveYun_Permission_Public_Read_Write]; |
| 324 | CNLivePutObjectRequest *putObjRequest = [[CNLivePutObjectRequest alloc] initWithAcl:ControlList grantAcl:nil]; | 304 | CNLivePutObjectRequest *putObjRequest = [[CNLivePutObjectRequest alloc] initWithAcl:ControlList grantAcl:nil]; |
| 325 | - NSString *fileName = [[NSBundle mainBundle] pathForResource:@"7.6M" ofType:@"mov"]; | 305 | + NSString *fileName = [[NSBundle mainBundle] pathForResource:@"cnlive" ofType:@"mp4"]; |
| 326 | putObjRequest.data = [NSData dataWithContentsOfFile:fileName options:NSDataReadingMappedIfSafe error:nil]; | 306 | putObjRequest.data = [NSData dataWithContentsOfFile:fileName options:NSDataReadingMappedIfSafe error:nil]; |
| 327 | _fileSize = putObjRequest.data.length; | 307 | _fileSize = putObjRequest.data.length; |
| 328 | 308 | ||
| 329 | putObjRequest.delegate = self; | 309 | putObjRequest.delegate = self; |
| 330 | - putObjRequest.filename = _bucketKey; | 310 | + putObjRequest.filename = [self bucketKey]; |
| 331 | putObjRequest.contentMd5 = [CNLiveSDKUtil base64md5FromData:putObjRequest.data]; | 311 | putObjRequest.contentMd5 = [CNLiveSDKUtil base64md5FromData:putObjRequest.data]; |
| 332 | [putObjRequest setCompleteRequest]; | 312 | [putObjRequest setCompleteRequest]; |
| 333 | 313 | ||
| @@ -358,9 +338,11 @@ | @@ -358,9 +338,11 @@ | ||
| 358 | } failure:^(NSDictionary *error) { | 338 | } failure:^(NSDictionary *error) { |
| 359 | NSLog(@"error %@",error); | 339 | NSLog(@"error %@",error); |
| 360 | }]; | 340 | }]; |
| 341 | + | ||
| 361 | } | 342 | } |
| 362 | 343 | ||
| 363 | -#pragma mark - Action | 344 | +#pragma mark - |
| 345 | +#pragma mark - ButtonAction | ||
| 364 | - (void)uploadBtnClicked:(UIButton *)btn | 346 | - (void)uploadBtnClicked:(UIButton *)btn |
| 365 | { | 347 | { |
| 366 | btn.selected =! btn.selected; | 348 | btn.selected =! btn.selected; |
| @@ -373,6 +355,7 @@ | @@ -373,6 +355,7 @@ | ||
| 373 | UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:199]; | 355 | UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:199]; |
| 374 | progressView.progress = 0; | 356 | progressView.progress = 0; |
| 375 | [btn setTitle:@"开始" forState:UIControlStateNormal]; | 357 | [btn setTitle:@"开始" forState:UIControlStateNormal]; |
| 358 | + _uploadType = kCNLiveUploadNormal; | ||
| 376 | return; | 359 | return; |
| 377 | } | 360 | } |
| 378 | [_muilt pause]; | 361 | [_muilt pause]; |
| @@ -380,6 +363,72 @@ | @@ -380,6 +363,72 @@ | ||
| 380 | } | 363 | } |
| 381 | } | 364 | } |
| 382 | 365 | ||
| 366 | +- (void)styleBtnAction | ||
| 367 | +{ | ||
| 368 | + [self uploadStyle]; | ||
| 369 | +} | ||
| 370 | + | ||
| 371 | +- (void)uploadStyle | ||
| 372 | +{ | ||
| 373 | + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"上传方式" message:@"默认上传方式为本地文件" preferredStyle:UIAlertControllerStyleActionSheet]; | ||
| 374 | + UIAlertAction *localAlert = [UIAlertAction actionWithTitle:@"本地文件" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | ||
| 375 | + _uploadType = kCNLiveUploadNormal; | ||
| 376 | + }]; | ||
| 377 | + [alert addAction:localAlert]; | ||
| 378 | + UIAlertAction *albumAlert = [UIAlertAction actionWithTitle:@"相册文件" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | ||
| 379 | + | ||
| 380 | + UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; | ||
| 381 | + imagePicker.delegate = self; | ||
| 382 | + imagePicker.allowsEditing = YES; | ||
| 383 | + imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//相机相册 | ||
| 384 | + // 设置所支持的媒体功能,即只能拍照,或则只能录像,或者两者都可以 | ||
| 385 | +#warning 此处需要区分视频还是图片文件,获取上传资源路径([CNLiveUpload getUploadResourceUrlWithBucketKey:uploadType:success:failure:])时需要用到此CNLiveYun_UploadType,Demo演示相册中 视频文件的上传 | ||
| 386 | + // NSString *requiredMediaType = ( NSString *)kUTTypeImage; | ||
| 387 | + NSString *requiredMediaType1 = ( NSString *)kUTTypeMovie; | ||
| 388 | + NSArray *arrMediaTypes=[NSArray arrayWithObjects: requiredMediaType1,nil];//requiredMediaType | ||
| 389 | + imagePicker.mediaTypes = arrMediaTypes; | ||
| 390 | + [self presentViewController:imagePicker animated:YES completion:NULL]; | ||
| 391 | + | ||
| 392 | + _uploadType = kCNLiveUploadAlasset; | ||
| 393 | + }]; | ||
| 394 | + [alert addAction:albumAlert]; | ||
| 395 | + UIAlertAction *cancelAlert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { | ||
| 396 | + [self dismissViewControllerAnimated:YES completion:NULL]; | ||
| 397 | + }]; | ||
| 398 | + [alert addAction:cancelAlert]; | ||
| 399 | + [self presentViewController:alert animated:YES completion:NULL]; | ||
| 400 | +} | ||
| 401 | + | ||
| 402 | +//#pragma mark 相册方法 | ||
| 403 | +///* | ||
| 404 | +// 这里,枚举模拟器相册所有的视频,模拟器只有一个只能获得开头传入的cnlive.mp4视频, | ||
| 405 | +// 具体工程使用时根据具体逻辑,获取到Alasset即可 | ||
| 406 | +//CNLiveClient 方法: | ||
| 407 | +// - (NSData *)getUploadPartDataWithPartNum:(NSInteger)partNum | ||
| 408 | +// partLength:(NSInteger)partlength | ||
| 409 | +// alassetURL:(NSURL *)alassetURL; | ||
| 410 | +// | ||
| 411 | +// - (NSData *)getUploadPartDataWithPartNum:(NSInteger)partNum | ||
| 412 | +// partLength:(NSInteger)partlength | ||
| 413 | +// Alasset:(ALAsset *)assets; | ||
| 414 | +// | ||
| 415 | +// - (ALAsset *)getAlassetFromAlassetURL:(NSURL *)alassetURL; | ||
| 416 | +// | ||
| 417 | +// */ | ||
| 418 | +#pragma mark - UIImagePickerControllerDelegate | ||
| 419 | +- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info | ||
| 420 | +{ | ||
| 421 | + NSURL *imageAssetUrl = [info objectForKey:UIImagePickerControllerReferenceURL]; | ||
| 422 | + _imageAssetUrl = imageAssetUrl; | ||
| 423 | + [self dismissViewControllerAnimated:YES completion:NULL]; | ||
| 424 | +} | ||
| 425 | + | ||
| 426 | +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker | ||
| 427 | +{ | ||
| 428 | + [self dismissViewControllerAnimated:YES completion:NULL]; | ||
| 429 | + NSLog(@"cancel"); | ||
| 430 | +} | ||
| 431 | + | ||
| 383 | #pragma mark - UITableView datasource | 432 | #pragma mark - UITableView datasource |
| 384 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | 433 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section |
| 385 | { | 434 | { |
| @@ -446,10 +495,11 @@ | @@ -446,10 +495,11 @@ | ||
| 446 | if ([request isKindOfClass:[KS3PutObjectRequest class]]) { | 495 | if ([request isKindOfClass:[KS3PutObjectRequest class]]) { |
| 447 | if (response.httpStatusCode == 200) { | 496 | if (response.httpStatusCode == 200) { |
| 448 | NSLog(@"单块上传成功"); | 497 | NSLog(@"单块上传成功"); |
| 449 | - [CNLiveUpload getUploadResourceUrlWithBucketKey:_bucketKey uploadType:CNLiveYun_UploadType_VideoFile success:^(NSString *resUrl) { | 498 | +#warning 根据选择的文件类型更改CNLiveYun_UploadType,Demo演示视频路径的获取 |
| 499 | + [CNLiveUpload getUploadResourceUrlWithBucketKey:[self bucketKey] uploadType:CNLiveYun_UploadType_VideoFile success:^(NSString *resUrl) { | ||
| 450 | NSLog(@"资源路径: %@",resUrl); | 500 | NSLog(@"资源路径: %@",resUrl); |
| 451 | } failure:^(NSDictionary *error) { | 501 | } failure:^(NSDictionary *error) { |
| 452 | - NSLog(@"error%@",error); | 502 | + NSLog(@"error: %@",error); |
| 453 | }]; | 503 | }]; |
| 454 | }else | 504 | }else |
| 455 | { | 505 | { |
| @@ -499,7 +549,8 @@ | @@ -499,7 +549,8 @@ | ||
| 499 | [mUserDefaults setInteger:0 forKey:keyUploadPartNum]; | 549 | [mUserDefaults setInteger:0 forKey:keyUploadPartNum]; |
| 500 | _uploadNum = 0 ; | 550 | _uploadNum = 0 ; |
| 501 | [mUserDefaults synchronize]; | 551 | [mUserDefaults synchronize]; |
| 502 | - [CNLiveUpload getUploadResourceUrlWithBucketKey:_bucketKey uploadType:CNLiveYun_UploadType_VideoFile success:^(NSString *resUrl) { | 552 | +#warning 根据选择的文件类型更改CNLiveYun_UploadType,Demo演示视频路径的获取 |
| 553 | + [CNLiveUpload getUploadResourceUrlWithBucketKey:[self bucketKey] uploadType:CNLiveYun_UploadType_VideoFile success:^(NSString *resUrl) { | ||
| 503 | NSLog(@"资源路径: %@",resUrl); | 554 | NSLog(@"资源路径: %@",resUrl); |
| 504 | } failure:^(NSDictionary *error) { | 555 | } failure:^(NSDictionary *error) { |
| 505 | NSLog(@"error: %@",error); | 556 | NSLog(@"error: %@",error); |
| @@ -576,11 +627,23 @@ | @@ -576,11 +627,23 @@ | ||
| 576 | } | 627 | } |
| 577 | } | 628 | } |
| 578 | 629 | ||
| 630 | +#pragma mark - Lazy | ||
| 631 | +- (UIButton *)styleBtn | ||
| 632 | +{ | ||
| 633 | + if (!_styleBtn) | ||
| 634 | + { | ||
| 635 | + _styleBtn = [[UIButton alloc] initWithFrame:CGRectMake(mScreenWidth *0.5-70, CGRectGetMaxY(self.tableView.frame) + 20, 140, 30)]; | ||
| 636 | + [_styleBtn setTitle:@"选择上传方式" forState:UIControlStateNormal]; | ||
| 637 | + [_styleBtn addTarget:self action:@selector(styleBtnAction) forControlEvents:UIControlEventTouchUpInside]; | ||
| 638 | + _styleBtn.backgroundColor = [UIColor redColor]; | ||
| 639 | + } | ||
| 640 | + return _styleBtn; | ||
| 641 | +} | ||
| 642 | + | ||
| 579 | - (void)didReceiveMemoryWarning { | 643 | - (void)didReceiveMemoryWarning { |
| 580 | [super didReceiveMemoryWarning]; | 644 | [super didReceiveMemoryWarning]; |
| 581 | // Dispose of any resources that can be recreated. | 645 | // Dispose of any resources that can be recreated. |
| 582 | } | 646 | } |
| 583 | - | ||
| 584 | /* | 647 | /* |
| 585 | #pragma mark - Navigation | 648 | #pragma mark - Navigation |
| 586 | 649 |