我目前正在通过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