2014-01-22 158 views
0

我目前正在通过this tutorial。我已经安装了AFNetworking,但是当我输入此代码时,我在第7行和第8行发现错误,说明Unknown type name AFJSONRequestOperationNo known class method for selector JSONRequestOperationWithRequest:request未知类型名称AFJSONRequestOperation

-(void)makeRestuarantRequests 
{ 
    NSURL *url = [NSURL URLWithString:@"A URL which returns JSON"]; 

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
//AFNetworking asynchronous url request 
AFJSONRequestOperation *operation = [AFJSONRequestOperation 
          JSONRequestOperationWithRequest:request 
          success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject) 
            { 
             NSLog(@"JSON RESULT %@", responseObject); 

            } 
          failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject) 
            { 
              NSLog(@"Request Failed: %@, %@", error, error.userInfo); 
            }]; 

[operation start]; 

} 

看来,我有一个文件丢失,其中包含一类,我需要,也许是AFJSONRequestOperation.m.h

修复的任何想法?

编辑:

AFNetworking download所有.h文件已通过AFNetworking.h被导入:

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

#ifndef _AFNETWORKING_ 
    #define _AFNETWORKING_ 

    #import "AFURLRequestSerialization.h" 
    #import "AFURLResponseSerialization.h" 
    #import "AFSecurityPolicy.h" 
    #import "AFNetworkReachabilityManager.h" 

    #import "AFURLConnectionOperation.h" 
    #import "AFHTTPRequestOperation.h" 
    #import "AFHTTPRequestOperationManager.h" 


#if ((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) || \ 
     (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000)) 
    #import "AFURLSessionManager.h" 
    #import "AFHTTPSessionManager.h" 
#endif 

#endif /* _AFNETWORKING_ */ 
+0

你错过了一个'#import' ... – trojanfoe

+0

所有这些文件都被导入:https://github.com/AFNetworking/AFNetworking/tree/master/AFNetworking正如我所说的,必须有一些缺失 – Sebastian

+0

全部他们?听起来有点矫枉过正。 – trojanfoe

回答

-1

添加System.Configuration框架。然后在pch中添加 #import。也许问题出现在配置框架中。

0

OP OP为时过晚我猜测,但我有这个问题,因为有两个副本AFNetworking漂浮在源文件夹周围。一个在我的CocoaPods安装中,另一个在之前未被删除。

我发现了这个错误信息的编译命令输出中找到了“AFNetworking”,它向我展示了AFNetworking的一个副本,这并不是我期待的。

倾销非pod副本修复了这一切。