我正在尝试调用网络指示器,然后在此代码之后将其关闭,如下所示,但它没有显示在状态栏中。我究竟做错了什么?我认为这只是网络活动完成得很快,但即使在睡眠状态下它似乎也不起作用。
-(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];
}
另外,如果有人想好心告诉我如何关闭图像视图,请随意,但我正要谷歌搜索。我是一个试图从教程等中学习的菜鸟。