@@ -50,8 +50,10 @@ - (IBAction)uploadAction:(UIButton *)sender {
5050
5151#ifdef YourToken
5252 NSString *path = [[NSBundle mainBundle ] pathForResource: @" UploadResource.dmg" ofType: nil ];
53- path = [[NSBundle mainBundle ] pathForResource: @" UploadResource_49M.zip" ofType: nil ];
54- path = [[NSBundle mainBundle ] pathForResource: @" UploadResource_1.44G.zip" ofType: nil ];
53+ path = [[NSBundle mainBundle ] pathForResource: @" image.png" ofType: nil ];
54+ path = [[NSBundle mainBundle ] pathForResource: @" image.jpg" ofType: nil ];
55+ path = [[NSBundle mainBundle ] pathForResource: @" UploadResource_6M.zip" ofType: nil ];
56+ // path = [[NSBundle mainBundle] pathForResource:@"UploadResource_1.44G.zip" ofType:nil];
5557
5658// NSFileManager *manager = [NSFileManager defaultManager];
5759// NSURL *desktopUrl = [manager URLsForDirectory:NSDesktopDirectory inDomains:NSUserDomainMask].firstObject;
@@ -90,10 +92,14 @@ - (void)changeUploadState:(UploadState)uploadState{
9092
9193- (void )uploadImageToQNFilePath : (NSString *)filePath {
9294
95+ // kQNGlobalConfiguration.isDnsOpen = false;
96+
97+
98+ NSString *key = [NSString stringWithFormat: @" iOS_Demo_%@ " , [NSDate date ]];
9399 self.token = YourToken;
94100 QNConfiguration *configuration = [QNConfiguration build: ^(QNConfigurationBuilder *builder) {
95- builder.useConcurrentResumeUpload = NO ;
96- builder.resumeUploadVersion = QNResumeUploadVersionV1 ;
101+ builder.useConcurrentResumeUpload = true ;
102+ builder.resumeUploadVersion = QNResumeUploadVersionV2 ;
97103 builder.recorder = [QNFileRecorder fileRecorderWithFolder: [NSHomeDirectory () stringByAppendingPathComponent: @" Documents" ] error: nil ];
98104 }];
99105 QNUploadManager *upManager = [[QNUploadManager alloc ] initWithConfiguration: configuration];
@@ -120,7 +126,7 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
120126
121127 long long fileSize = [[[NSFileManager defaultManager ] attributesOfItemAtPath: filePath error: nil ] fileSize ];
122128 NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath: filePath];
123- [upManager putInputStream: stream sourceId: filePath.lastPathComponent size: fileSize fileName: filePath.lastPathComponent key: @" DemoResource_1.44G " token: self .token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
129+ [upManager putInputStream: stream sourceId: filePath.lastPathComponent size: fileSize fileName: filePath.lastPathComponent key: key token: self .token complete: ^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
124130 NSLog (@" info ===== %@ " , info);
125131 NSLog (@" resp ===== %@ " , resp);
126132
@@ -130,8 +136,8 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
130136
131137// NSURL *url = [NSURL fileURLWithPath:filePath];
132138// PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
133- // PHAsset *asset = fetchResult.firstObject ;
134- // [upManager putPHAsset:asset key:@"DemoResource" token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
139+ // PHAsset *asset = [self getPHAssert] ;
140+ // [upManager putPHAsset:asset key:key token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
135141// NSLog(@"info ===== %@", info);
136142// NSLog(@"resp ===== %@", resp);
137143//
@@ -141,6 +147,41 @@ - (void)uploadImageToQNFilePath:(NSString *)filePath {
141147// option:uploadOption];
142148}
143149
150+ - (PHAsset *)getPHAssert {
151+
152+ PHFetchOptions *option = [[PHFetchOptions alloc ] init ];
153+ option.predicate = [NSPredicate predicateWithFormat: @" mediaType == %ld" ,PHAssetMediaTypeVideo];
154+ option.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey: @" creationDate" ascending: NO ]];
155+
156+ __block PHAsset *phAsset = nil ;
157+ // fetchAssetCollectionsWithType
158+ PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType: PHAssetCollectionTypeSmartAlbum subtype: PHAssetCollectionSubtypeAlbumRegular options: nil ];
159+ for (PHAssetCollection *collection in smartAlbums) {
160+ // 有可能是PHCollectionList类的的对象,过滤掉
161+ if (![collection isKindOfClass: [PHAssetCollection class ]]) continue ;
162+ // 过滤空相册
163+ if (collection.estimatedAssetCount <= 0 ) continue ;
164+
165+ PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection: collection options: option];
166+
167+ [fetchResult enumerateObjectsUsingBlock: ^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
168+
169+ phAsset = (PHAsset *)obj;
170+ // 可通过此PHAsset用下边方法分别获取时常、地址及缩略图
171+
172+ if (phAsset) {
173+ *stop = true ;
174+ }
175+ }];
176+
177+ if (phAsset) {
178+ break ;
179+ }
180+ }
181+
182+ return phAsset;
183+ }
184+
144185- (void )gotoImageLibrary {
145186 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
146187 UIImagePickerController *picker = [[UIImagePickerController alloc ] init ];
0 commit comments