我刚刚构建了我的第一个应用程序,现在我开始在我的手机上测试它。当我在构建应用程序后首次启动它时,它看起来很棒,启动图像出现,然后我的 json 数据通过 NSURL 加载并正确显示在应用程序上。但是当我关闭应用程序,通过 php 和 mysql 更新数据并重新打开它时,启动图像不会出现,我的应用程序也没有更新。是否可以让应用程序像我第一次启动时那样启动,始终有启动图像并获取新数据?
如果有帮助,这是我的代码。
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadJSON];
}
- (void)loadJSON
{
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Error" message: @"Connection Failed" delegate: self cancelButtonTitle:@"Refresh" otherButtonTitles:nil]; [alert show]; [alert release];
});
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url = [NSURL URLWithString:@"http://url.com/GetData.php"];
NSData *data = [NSData dataWithContentsOfURL:url options:0 error:nil];
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSArray *firstItemArray = array[0];
NSString *yesNoString = firstItemArray[0];
NSString *dateString = firstItemArray[1];
NSString *timeString = firstItemArray[2];
NSString *homeString = firstItemArray[3];
NSString *awayString = firstItemArray[4];
NSString *lastUpdatedString = firstItemArray[5];
dispatch_async(dispatch_get_main_queue(), ^{
self.YesOrNo.text = yesNoString;
self.date.text = [@"For " stringByAppendingString:dateString];
self.time.text = timeString;
self.home.text = homeString;
self.away.text = awayString;
self.lastUpdated.text = lastUpdatedString;
self.lastUpdatedText.text = @"Last Updated";
self.vs.text = @"vs";
});
});
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[self loadJSON];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_YesOrNo release];
[_date release];
[_time release];
[_vs release];
[_home release];
[_away release];
[_lastUpdatedText release];
[_lastUpdated release];
[super dealloc];
}
@end
如果有人能指出我正确的方向,那将是非常好的,我将不胜感激,谢谢。
最佳答案
当您在运行应用程序时按下圆形主页按钮时,它只是将其置于后台,继续以一种紧张症状态运行。当您再次点击它的图标时,它只会唤醒,不会重新启动。如果你想让你的应用程序在用户点击主页按钮时完全退出,请使用 info.plist 选项“UIApplicationExitsOnSuspend”,也称为“应用程序不在后台运行”。在您的 info.plist 中将其设置为 YES,您每次都会重新开始。您可以通过在项目导航器模式下单击 Xcode 中的项目来访问它,然后选择顶部中间的“信息”选项卡。
关于iphone - Objective-C 在 iPhone 上测试应用程序,更新数据,数据没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17915231/