我正在尝试将我的代码从ASIHTTPRequest更改为AFNetworking.目前我想选择10-15个不同的HTTP URL(文件)并将它们下载到文档文件夹.
使用ASIHTTPRequest非常简单
[myQueue setDownloadProgressDelegate:myUIProgressView];
Run Code Online (Sandbox Code Playgroud)
在AFNetworking中我无法弄清楚如何做到这一点.我有以下代码下载文件,存储它们并在文件成功下载时通知,但我无法为此队列创建总大小的进度条.
for (i=0; i<3; i++) {
NSString *urlpath = [NSString stringWithFormat:@"http://www.domain.com/file.zip"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlpath]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"testFile%i.zip",i]];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation setDownloadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
NSLog(@"Sent %d of %d …Run Code Online (Sandbox Code Playgroud) 我有一个包含ARC代码和非ARC代码的应用程序.当我尝试将非ARC代码编译为ARC时,编译器将捕获.如果在没有ARC的情况下错误地编译ARC代码,如何导致编译时错误/通知?显然,代码将编译.它会泄漏.静态分析仪将解决问题.我宁愿找到一种方法来保留编译指示或在我的ARC代码中定义.
以下内容由Apple定义objc-api.h:
/* OBJC_ARC_UNAVAILABLE: unavailable with -fobjc-arc */
#if !defined(OBJC_ARC_UNAVAILABLE)
# if __has_feature(objc_arr)
# define OBJC_ARC_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
# else
# define OBJC_ARC_UNAVAILABLE
# endif
#endif
Run Code Online (Sandbox Code Playgroud)
我的C-macro-fu很弱.我该如何使用它?或者,或许有更好的符号可供检查?
PS我问,因为我从可重用的库中构建了很多应用程序.我想确保以正确的方式编译每个文件.
我使用的是UISplitViewController上ARC,但似乎几个旋转后,事件将崩溃:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x80069f69
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x32461f78 objc_msgSend + 16
1 UIKit 0x3588b280 -[UISplitViewController _calculateDelegateHiddenMasterOrientations] + 52
2 UIKit 0x3588cca8 -[UISplitViewController setViewControllers:] + 1344
3 PUC 0x000d0a42 0x1000 + 850498
4 UIKit 0x35644ade -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 938
5 UIKit 0x356be7a4 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 152
Run Code Online (Sandbox Code Playgroud)
此外,当我启动应用程序时,我收到此错误:
Splitview controller <PUCSplitViewController: 0x36c290> is expected to have a master view controller before …Run Code Online (Sandbox Code Playgroud)