0
这里我使用GET方法从服务器获取数据,但是当我最小化时,应用程序会在后台运行,并且在我重新打开后,我看不到这是我以前获取的任何数据,我只看到数据的第一次,当我最小化,然后重新打开这里迷路是我的代码使用“GET”方法获取数据当我从后台重新打开应用程序时丢失
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://198.178.4.9:89/mybite_joomla/cron/webapi.php?task=webapi.viewProfile"]cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10
];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];
NSError *err;
NSURLResponse *response;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingMutableContainers error: &err];{
for (NSDictionary *dict in jsonArray) {
nameTextView.text =[jsonArray valueForKey:@"name"];
usernameTextView.text =[jsonArray valueForKey : @"username"];
emailTextView.text=[jsonArray valueForKey : @"email"];
cityTextView.text =[jsonArray valueForKey : @"city"];
stateTextView.text =[jsonArray valueForKey : @"state"];
countryTextView.text =[jsonArray valueForKey : @"country"];
}
}
我可以使用存储NSUserDefaults的会是在我的案件有帮助的数据,如果应用程序仍然在后台长时间处于暂停状态得到@Lion – vicky
是的,你可以用'NSUserDefaults' – Lion
并没有使用的声明NSDictionary * jsonArray作为属性...即使应用程序在后台进入几秒钟我失去了数据@Lion – vicky