我目前正在通過this tutorial。我已經安裝了AFNetworking,但是當我輸入此代碼時,我在第7行和第8行發現錯誤,說明Unknown type name AFJSONRequestOperation
和No 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_ */
你錯過了一個'#import' ... – trojanfoe
所有這些文件都被導入:https://github.com/AFNetworking/AFNetworking/tree/master/AFNetworking正如我所說的,必須有一些缺失 – Sebastian
全部他們?聽起來有點矯枉過正。 – trojanfoe