我正面临一个强大的与自动发布的问题:
我使用一个具有强NSProgress的对象来管理文件下载。为了下载,我使用downloadtaskwithrequest从AFNetworking。我的问题是,这个方法采用了一个与我的强NSProgress * __autoreleasing *不兼容的NSProgress:
这是我的对象拥有它的NSProgress:
@interface MyDocument ()
@property(nonatomic, strong) NSProgress *progress;
@end
@implementation MyDocument ()
-(void)download
{
[myApiClient downloadFileWithUrl:_url progress:_progress]
}
@end这是处理下载的SessionManager:
-(void)downloadFileFromUrl:(NSString*)url progress:(NSProgress * __strong *)progress
{
NSURLSessionDownloadTask *downloadTask = [self downloadTaskWithRequest:request
progress:progress
destination:^NSURL *(NSURL *targetPath, NSURLResponse *response)
{ ... }
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error)
{ ... }];
}这是与行progress:progress有关的错误:
Passing address of non-local object to __autoreleasing parameter for write-back发布于 2015-02-01 23:26:50
初始化downloadTaskWithRequest对象的是NSProgress,所以我不能直接给它一个NSProgress,它是我的对象的属性,我必须创建另一个NSProgress对象,并在需要时更新我的属性:
-(void)downloadFileFromUrl:(NSString*)url progress:(NSProgress * __strong *)progress
{
NSProgress *localProgress = nil;
NSURLSessionDownloadTask *downloadTask = [self downloadTaskWithRequest:request
progress:localProgress
destination:^NSURL *(NSURL *targetPath, NSURLResponse *response)
{ ... }
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error)
{ ... }];
// Update my property here :
*progress = localProgress;
}发布于 2015-01-31 14:12:39
您需要将指针传递到NSProgress对象,而不是将对象作为参数传递。**意味着必须将指针传递到指向现有对象的指针。
[myApiClient downloadFileWithUrl:_url progress:&_progress];https://stackoverflow.com/questions/28252465
复制相似问题