尝试创建请求只是为了抛出运行时错误。启动请求的方法:
- (void)loadMemberData {
//build URL
NSMutableString *url = [[NSMutableString alloc] initWithString:appDelegate.apiURL];
[url appendFormat:@"&subaction=singlestat&memberID=%d", [[NSUserDefaults standardUserDefaults] integerForKey:@"memberID"]];
NSURL *tempURL = [[NSURL alloc] initWithString:url];
NSLog(@"URL: %@", tempURL);
//Create conn
NSURLRequest *request = [[NSURLRequest alloc] requestWithURL:tempURL];
NSLog(@"%@", request);
//conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
//[request release];
}
网址正确记录。我甚至检查了对象类型,以确保一切正确,一切似乎都很好。没有编译时错误或警告。 Stack Trace&经度:
[Session started at 2011-03-09 15:02:32 -0500.]
2011-03-09 15:02:33.807 NTR Beer Club[17702:207] URL: https://mydomain.com/path/to/file.php?action=get_app_data&subaction=singlestat&memberID=117
2011-03-09 15:02:33.809 NTR Beer Club[17702:207] -[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0
2011-03-09 15:02:33.811 NTR Beer Club[17702:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLRequest requestWithURL:]: unrecognized selector sent to instance 0x4b02cf0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db7be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f0c5c2 objc_exception_throw + 47
2 CoreFoundation 0x00db96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d29366 ___forwarding___ + 966
4 CoreFoundation 0x00d28f22 _CF_forwarding_prep_0 + 50
5 NTR Beer Club 0x00002190 -[MyStats loadMemberData] + 358
6 NTR Beer Club 0x000022c8 -[MyStats viewDidLoad] + 215
7 UIKit 0x004b64f0 -[UINib instantiateWithOwner:options:] + 1556
8 UIKit 0x004b8081 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x002c2943 -[UIApplication _loadMainNibFile] + 172
10 UIKit 0x002c34ca -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
11 UIKit 0x002cddb2 -[UIApplication handleEvent:withNewEvent:] + 1533
12 UIKit 0x002c6202 -[UIApplication sendEvent:] + 71
13 UIKit 0x002cb732 _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x016eda36 PurpleEventCallback + 1550
15 CoreFoundation 0x00d99064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00cf96f7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00cf6983 __CFRunLoopRun + 979
18 CoreFoundation 0x00cf6240 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00cf6161 CFRunLoopRunInMode + 97
20 UIKit 0x002c2fa8 -[UIApplication _run] + 636
21 UIKit 0x002cf42e UIApplicationMain + 1160
22 NTR Beer Club 0x00001b98 main + 102
23 NTR Beer Club 0x00001b29 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
答案 0 :(得分:2)
你应该这样做
NSURLRequest *request = [NSURLRequest requestWithURL:tempURL];
requestWithURL:
创建NSURLRequest
的{{1}}个对象 - d。
实际的错误消息显示“无法识别的选择器”,因为autorelease
是一个类方法,但您正在使用它像实例方法。