【发布时间】:2017-02-22 06:48:28
【问题描述】:
我有一个方法,该方法返回了 nsdata 值,但我不知道如何从 NSURLSessionDataTask 块中获取返回值。以及如何调用 getDownloadFileData 方法。任务代码是:-
来电者:
NSData *getFileDataResult = [self getDownloadFileData:pathString];
方法:
- (NSData*) getDownloadFileData : (NSString*) filePath {
NSURLSessionDataTask *downloadFile = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:filePath] completionHandler:^(NSData *fileData, NSURLResponse *response, NSError *error){
// .....
// fileData should return out.
[downloadFile resume];
});
// I want to return the fileData after download completion.
// how to return?
}
有人可以帮帮我吗?
非常感谢。
【问题讨论】:
-
你可以使用完成块,看看stackoverflow.com/questions/21436831/…
标签: ios objective-c block