Skip to content

Commit 057b7f8

Browse files
committed
Merge pull request #40 from longbai/url_conv
ui callback
2 parents 0f4341f + b4f8586 commit 057b7f8

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

QiniuSDK/Common/QNAsyncRun.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
typedef void (^QNRun)(void);
1010

1111
void QNAsyncRun(QNRun run);
12+
13+
void QNAsyncRunInMain(QNRun run);

QiniuSDK/Common/QNAsyncRun.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ void QNAsyncRun(QNRun run) {
1414
run();
1515
});
1616
}
17+
18+
void QNAsyncRunInMain(QNRun run) {
19+
dispatch_async(dispatch_get_main_queue(), ^(void) {
20+
run();
21+
});
22+
}

QiniuSDK/Storage/QNUploadManager.m

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ + (BOOL)checkAndNotifyError:(NSString *)key
116116
desc = @"no token";
117117
}
118118
if (desc != nil) {
119-
QNAsyncRun( ^{
119+
QNAsyncRunInMain( ^{
120120
completionHandler([QNResponseInfo responseInfoWithInvalidArgument:desc], key, nil);
121121
});
122122
return YES;
@@ -132,11 +132,18 @@ - (void)putData:(NSData *)data
132132
if ([QNUploadManager checkAndNotifyError:key token:token data:data file:nil complete:completionHandler]) {
133133
return;
134134
}
135+
136+
QNUpCompletionHandler complete = ^(QNResponseInfo *info, NSString *key, NSDictionary *resp)
137+
{
138+
QNAsyncRunInMain( ^{
139+
completionHandler(info, key, resp);
140+
});
141+
};
135142
QNFormUpload *up = [[QNFormUpload alloc]
136143
initWithData:data
137144
withKey:key
138145
withToken:token
139-
withCompletionHandler:completionHandler
146+
withCompletionHandler:complete
140147
withOption:option
141148
withHttpManager:_httpManager
142149
withConfiguration:_config];
@@ -159,7 +166,7 @@ - (void)putFile:(NSString *)filePath
159166
NSDictionary *fileAttr = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
160167

161168
if (error) {
162-
QNAsyncRun( ^{
169+
QNAsyncRunInMain( ^{
163170
QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError:error];
164171
completionHandler(info, key, nil);
165172
});
@@ -170,7 +177,7 @@ - (void)putFile:(NSString *)filePath
170177
UInt32 fileSize = [fileSizeNumber intValue];
171178
NSData *data = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
172179
if (error) {
173-
QNAsyncRun( ^{
180+
QNAsyncRunInMain( ^{
174181
QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError:error];
175182
completionHandler(info, key, nil);
176183
});
@@ -183,7 +190,9 @@ - (void)putFile:(NSString *)filePath
183190

184191
QNUpCompletionHandler complete = ^(QNResponseInfo *info, NSString *key, NSDictionary *resp)
185192
{
186-
completionHandler(info, key, resp);
193+
QNAsyncRunInMain( ^{
194+
completionHandler(info, key, resp);
195+
});
187196
};
188197

189198
NSDate *modifyTime = fileAttr[NSFileModificationDate];

0 commit comments

Comments
 (0)