ASIHTTPRequest를 사용하여 iOS 용 앱을 만들려고하는데 사용하는 데 문제가 있습니다. 내 문제를 설명하기 위해 테스트 프로젝트를 업로드했습니다.이 프로젝트는 http://uploads.demaweb.dk/ASIHTTPRequestTester.zip에서 다운로드 할 수 있습니다. 동기 방법은 잘 작동되지만,ASIHTTPRequestTester : 비동기가 작동하지 않습니다.
#import "WebService.h"
#import "ASIHTTPRequest.h"
@implementation WebService
- (void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"requestFinished");
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSLog(@"requestFailed");
}
- (void) testSynchronous {
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSLog(@"starting Synchronous");
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSLog(@"got response");
}
}
- (void) testAsynchronous {
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
NSLog(@"starting Asynchronous");
[request startAsynchronous];
}
@end
비동기가 전혀 작동하지 않습니다 :
나는 ASIHTTPRequestDelegate
프로토콜을 사용하십시오 WebService 클래스를 만들었습니다. 먼저 requestFinished와 requestFailed는 호출되지 않았고 지금은 EXC_BAD_ACCESS를 얻고 있습니다. 두 가지 테스트 메소드는 내 ViewController의 viewDidLoad
에서 호출됩니다. 누군가가 나를 도와 줄 수 있기를 바랍니다.
EDIT1 : this topic 당으로 , 그것 때문에 내 프로젝트를 사용할 수있는 Automatic Reference Counting
가능하다. 화제 통보는 [self retain]
를 추가하고, 그러나 ARC를 켜서 이것을 할 수 없다. 이 문제를 해결할 수있는 사람이 있습니까?
EDIT2 : MrMage에서 답변을 업데이트합니다.
@interface ViewController()
@property (nonatomic,strong) WebService *ws;
@end
@implementation ViewController
@synthesize ws = _ws;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self setWs:[[WebService alloc] init]];
[self.ws testSynchronous];
[self.ws testAsynchronous];
}
@end
답변 해 주셔서 감사합니다. ViewController에 강력한 속성을 추가 한 내'edit2'를 보시기 바랍니다. 잘 작동하지만 더 나은 방법이 있습니까? – dhrm