iPhone Developer Tips Visitor Stats: 126,691 Pageviews and 94,296 visitors in the past 30 days.
|
I found that sometimes you may be doing something in your iPhone application that requires the user to wait while it completes. Often this is a network related activity, but in other cases it may not be. In my case I was parsing the response from a network connection and wanted the network activity indicator to keep spinning even though it had already downloaded the content.
Here is a quick tip on how to trigger the display of the network activity indicator (spinning icon at the top left of the screen) on an iPhone from within your application:
1
2
3
4
5
6
7
| // start the indicator ...
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// Do something that may take some time to complete ...
// stop the indicator ...
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; |
Share with iOS Developers:
Comments
6 Responses to “Showing Network Activity When there Isn’t Any”
Leave Comment
FYI, I have confirmed that this doesn’t show up in the Simulator (2.2.1), but DOES work on the device.
I heard that it does work on the simulator but only if you are connected to the net via ethernet. Weird!
Editor’s Note: This is in reference to the SDK 3.x., where the spinner now works in the simulator
Be advised, Apple specifically states in the HIG that the activity indicator in the status bar is for network activity only. Any other activity should be handled with your own activity indicator elsewhere.
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/ApplicationControls/ApplicationControls.html
Hello there,
I’m new I’m to iPhone dev.
I’m trying to implement NetworkActivityIndicatorVisible while sending an email.
If I write the below mentioned code, then the activity indicator keeps on spinning, even after the mail is sent.
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
[self dismissModalViewControllerAnimated:YES];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
If I add this code, after …YES];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
then the activity indicator disappears.
I want the activity indicator to be visible as long as the mail is not sent (task performing in the background). And once it’s sent the activity indicator stops spinning and disappears.
Would really appreciate if you could solve this problem.
Cheers!
Sid, what I think you want to do is to start the activity indicator before sending the email, and once complete, didFinishWithResult is called and you can then stop the indicator.
Thanks so much. It worked.