Ich habe eine Methode, die Methode habe den Nsdata-Wert zurückgegeben, aber ich weiß nicht, wie der Rückgabewert von NSURLSessionDataTask Block erhalten. und wie die getDownloadFileData methods.Code für Aufgabe nennen ist: -Wie bekomme ich den Rückgabewert von NSURLSessionDataTask und Call Block?
Anrufer:
NSData *getFileDataResult = [self getDownloadFileData:pathString];
Methode:
- (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?
}
jemand kann mir eine Hand?
Vielen Dank.
können Sie Abschlussblöcke verwenden, schauen Sie sich http://StackOverflow.com/Questions/21436831/How-to-Write-an-Objective-c-Completion-Block – raki