Trying to create a request only to have a runtime error thrown. Method initiating the request:
- (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];
}
The URL logs correctly. I have even checked the object type to make sure everything is correct, and all seems good. No compile time errors or warnings. Stack Trace & Log:
[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'
You should be doing
NSURLRequest *request = [NSURLRequest requestWithURL:tempURL];
The requestWithURL:
creates NSURLRequest
objects that are autorelease
-d.
The actual error message says "unrecognized selector" because requestWithURL:
is a class method, but you are using it like an instance method.
User contributions licensed under CC BY-SA 3.0