Alosyius
Alosyius

Reputation: 9111

HTTP GET request working in iOS simulator but not on iPhone device

My app is calling a basic PHP script that outputs JSON data.

I am calling my PHP script like this:

NSString *buildURL = [NSString stringWithFormat: @"http://xxxx.com/api.php?action=authenticate_user&email=%@&password=%@&deviceToken=%@", _emailAddress, _password, deviceToken];
NSURL *url = [NSURL URLWithString: buildURL];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *ret = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

// Parse the result
NSString *ret2 = [ret stringByReplacingOccurrencesOfString:@"null" withString:@""];
NSError* error;
NSDictionary *JSON =
[NSJSONSerialization JSONObjectWithData: [ret2 dataUsingEncoding:NSUTF8StringEncoding]
                                options: NSJSONReadingMutableContainers
                                  error: &error];

NSString* status = [JSON objectForKey:@"status"];
NSString* email = [JSON objectForKey:@"email"];
NSString* userID = [JSON objectForKey:@"userID"];
NSString* agentID = [JSON objectForKey:@"agentID"];
NSString* picture = [JSON objectForKey:@"picture"];

For some reason when running this code on my iPhone all the variables are (null), but in the simulator I get the correct data.

The output of my php script is:

{"status":"1", "agentName":"Bill", "picture":"http://xxxx.com/thumb_ad1-8908968097.jpg", "departmentName":"", "email":"[email protected]", "agentID":"513", "userID":"3"}null

Any ideas what I'm doing wrong?

Upvotes: 3

Views: 1422

Answers (1)

Toseef Khilji
Toseef Khilji

Reputation: 17409

I surely guess that your webservice is not live (your web service are on local server make them global).

Device is not connected with your current php server , from where you called webservice, from simulator it gives output because mac os is connected with server.

Upvotes: 2

Related Questions