分配委托时无法识别的选择器崩溃

时间:2017-10-21 03:19:03

标签: ios objective-c xcode

我正在使用NSXMLParser来解析来自卡处理器的xml响应。这段代码已经运行了几年,直到升级到xcode 9并在iOS11上运行。现在我得到一个无法识别的选择器,未捕获的异常崩溃。我在iPhone 7设备上运行xcode。

NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (!error) {
        DLog(@"received XML response: %@", response);
        [MBProgressHUD hideAllHUDsForView:[[UIApplication sharedApplication] keyWindow] animated:YES];
        [self performSelectorOnMainThread:@selector(XMLRequestSucceeded:) withObject:response waitUntilDone:YES];
    } else {
       ......

(I get to here:)
-(void) XMLRequestSucceeded:(NSXMLParser *) response {
    response.delegate = self;   *** crashes here ****
    self.responseDict = [NSMutableDictionary dictionaryWithCapacity:20];
    [response parse];

    DLog(@"parser result %@", responseDict);

这是标题:

.....
#import <Foundation/NSXMLParser.h>

@protocol NSXMLParserDelegate;

@interface PaymentProcessor : NSObject  <NSXMLParserDelegate>  {  
}
.....

错误消息:

  

[NSHTTPURLResponse setDelegate:]:发送到的无法识别的选择器   实例0x1c44356a0

xcode 9或iOS11是否有可能导致此次崩溃的变化?谢谢你输入。

1 个答案:

答案 0 :(得分:0)

我解决了我的问题(在疯狂的评论的帮助下)。我将传递给XMLRequestSucceeded的参数更改为responseObject而不是response。我现在传递要解析的NSXMLParser数据。说得通。我只是不知道为什么这段代码成功运作了2年多了!

修正:

NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (!error) {
        DLog(@"received XML response: %@", response);
        [MBProgressHUD hideAllHUDsForView:[[UIApplication sharedApplication] keyWindow] animated:YES];
        [self performSelectorOnMainThread:@selector(XMLRequestSucceeded:) withObject:responseObject waitUntilDone:YES];
    } else {
       ......