我正在尝试调用网络指示符,然后在此代码之后将其关闭,如下所示,但它不会显示在状态栏中。我究竟做错了什么?我认为只是网络活动快速完成,但即使在睡眠状态下它似乎也无法正常工作。
-(void)applicationDidBecomeActive:(UIApplication *)application {
UIImageView *loadingImage = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
loadingImage.image = [UIImage imageNamed:@"loading-splash.png"];
loadingImage.contentMode = UIViewContentModeCenter;
[self.window addSubview:loadingImage];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: @"http://mysite.tk/in-app/net.test" ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
NSLog(@"%@", serverOutput);
sleep(1);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if([serverOutput isEqualToString:@"internet is working"])
{
[SVStatusHUD showWithImage:[UIImage imageNamed:@"connected.png"] status:@"Connected"];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Connection Unsuccesful" message:@"App Requests has failed connecting to the server. Some or all of App Requests functions may not work. Please check your internet connection."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertsuccess show];
[alertsuccess release];
}
[loadingImage release];
}
此外,如果有人想要善意告诉我如何解雇图像视图也感觉自由,但我正准备谷歌。我是一个试图从教程等学习的菜鸟。
答案 0 :(得分:0)
您需要使用类似的东西在单独的线程中显示和隐藏指标。
dispatch_async(dispatch_get_main_queue(), ^{
// Put any code you want to execute in the main thread here.
});