我有一個方法,該方法有返回nsdata值,但我不知道如何從NSURLSessionDataTask塊得到返回值。如何調用getDownloadFileData methods.Code任務是: -如何從NSURLSessionDataTask和調用塊獲取返回值?
來電者:
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?
}
有誰能給我個忙嗎?
非常感謝。
可以使用完畢塊,看看http://stackoverflow.com/questions/21436831/how-to-write-an-objective-c-completion-block – raki