我正在尝试将OAuthConsumer与API进行交互。当“self”关键字为空时,我遇到了委托问题。
当下面的代码放在唯一的viewController里面时,一切正常。当代码放在一个名为wpOAuth的类中时,然后从viewController调用“self”关键字为空,这会导致此错误: requestTokenTicket:didFinishWithData:]:无法识别的选择器发送到实例0x7172ac0
-(void)getKey:(UIViewController *) uiViewController{
NSLog(@"\n\nGet Key!!!!!");
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"fsdfsdsdfsdfsdf"
secret:@"sdfdsfsdfsdf"];
NSURL *url = [NSURL URLWithString:@"http://api-public.netflix.com/oauth/request_token"];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:nil // we don't have a Token yet
realm:nil // our service provider doesn't specify a realm
signatureProvider:nil]; // use the default method, HMAC-SHA1
[request setHTTPMethod:@"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(requestTokenTicket:didFinishWithData:)
didFailSelector:@selector(requestTokenTicket:didFailWithError:)];
}
- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data {
if (ticket.didSucceed) {
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
//requestToken = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
NSLog(@"%@",[[OAToken alloc] initWithHTTPResponseBody:responseBody]);
NSLog(@"\nticket is????????????????????????????= %@ ",ticket.body);
}
}
任何关于self关键字为空的原因都会非常感激!
谢谢, 4D
答案 0 :(得分:0)
我不熟悉以这种方式处理的代理,但我认为您需要在标头中添加- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data;
来定义方法。看起来OADataFetcher
没有使用协议,所以当它试图在你的对象上调用方法时,它是不可见的,因为你没有定义它。