0

我正在尝试合并 OAuthConsumer 以与 API 交互。当“self”关键字为空时,我遇到了委托问题。

当下面的代码放在唯一的 viewController 内时,一切正常。当代码放在名为 wpOAuth 的类中时,然后从 viewController 调用“self”关键字为空,这会导致此错误: requestTokenTicket:didFinishWithData:]: unrecognized selector sent to instance 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

4

1 回答 1

0

我不熟悉以这种方式处理的委托,但我认为您需要添加- (void)requestTokenTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data;到您的标题中以定义该方法。看起来OADataFetcher没有使用协议,因此当它尝试调用对象上的方法时,它是不可见的,因为您没有定义它。

于 2012-11-27T18:14:00.147 回答