2014-01-22 153 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副本修復了這一切。