我的应用程序应该每隔 10 秒左右使用特定的 url 从服务器发出请求,更改 url 中的一些属性,然后在另一个名为“updateView”的视图中显示请求,或者如果发生任何网络错误,则显示错误。第一部分工作正常,但如果我切换 wifi,例如应用程序崩溃。我该如何解决这个问题以及如何显示各种错误?提前致谢!!这是我的代码(这是每 10 秒调用一次的方法):
- (void)serverUpdate{
CLLocationCoordinate2D newCoords = self.location.coordinate;
gpsUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://odgps.de/chris/navextest?objectid=3&latitude=%2.4fN&longitude=%2.4fE&heading=61.56&velocity=5.21&altitude=%f&message=Eisberg+voraus%21", newCoords.latitude, newCoords.longitude, self.location.altitude]];
self.pageData = [NSString stringWithContentsOfURL:gpsUrl];
[updateView.transmissions insertObject:pageData atIndex:counter];
if (counter == 100) {
[updateView.transmissions removeAllObjects];
counter = -1;
}
counter = counter + 1;
[updateView.tableView reloadData];
self.sendToServerSuccessful = self.sendToServerSuccessful + 1;
[self.tableView reloadData];
}