ios - How to use json data from localhost in objective-c? -


- (void)viewdidload {     [super viewdidload];     // additional setup after loading view.      nsurl *site_url = [nsurl urlwithstring:[nsstring stringwithformat:@"%@/json/data/post?sid=%@", secure, passcode]];      nsdata *jsondata = [nsdata datawithcontentsofurl:site_url];     nserror *error = nil;     nsdictionary *datadictionary = [nsjsonserialization jsonobjectwithdata:jsondata options:0 error:&error];      self.items = datadictionary;   } 

i trying parse json data. works fine data live server. however, when change link http://localhost:8090. stops working.

terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'data parameter nil' 

i can access data web browser. know why that?

does work on emulator , not on real device?

you should never use localhost when developing apps, use local ip server instead. localhost machine make call server. when try on emulator , have server on same machine works because same. when try on real device, localhost device, , device doesn't have server installed, fail. btw, test on real device, has connected same network.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -