Simple iOS Get Request Not Pulling in Data
Posted
by
user2793987
on Stack Overflow
See other posts from Stack Overflow
or by user2793987
Published on 2014-06-06T23:51:25Z
Indexed on
2014/06/07
3:26 UTC
Read the original article
Hit count: 124
I have a very simple get request that doesn't return data on my script. The script is fine when viewed in the web browser but the app does not pull in the data. Any other script works with this code in the app. I'm unsure of what to do because there shouldn't be a reason for this to not work. Please let me know if you need more information. Here's the script: https://shipstudent.com/complaint_desk/similarPosts.php?username=noah
//retrieve saved username from user defaults (it's noah)
NSUserDefaults *eUser = [NSUserDefaults standardUserDefaults];
savedUser = [eUser objectForKey:@"user"];
NSLog(@"%@",savedUser);
in ViewDidLoad:
NSString *categoryParam = [NSString stringWithFormat:@"https://shipstudent.com/complaint_desk/similarPosts.php?username=%@", savedUser];
NSURL *url = [NSURL URLWithString:categoryParam];
NSMutableURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:30.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection==nil) {
NSLog(@"Invalid request");
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
postData = [[NSMutableData alloc]init];
NSLog(@"Response received");
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[postData appendData:data];
NSLog(@"Data received");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
similarPosts = [NSJSONSerialization JSONObjectWithData:postData options:kNilOptions error:nil];
[postsTbl reloadData];
for (id postObject in similarPosts)
{
NSLog(@"Relatable Post: %@",postObject);
}
}
© Stack Overflow or respective owner