tags:

views:

2565

answers:

2

I have noticed that some apps like Safari and Mail show a loading indicator in the status bar (the bar at the very top of the phone) when they are accessing the network. Is there a way to do the same thing in SDK apps, or is this an Apple only thing?

+16  A: 

It's in UIApplication:

UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
Stephen Darlington
Thanks that works perfectly. Just a side note: the simulator seems to ignore this value, which made me think at first it didn't work.
rustyshelf
+1  A: 

I've found the following macros pretty useful!

#define ShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
#define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO

So you can just call ShowNetworkActivityIndicator(); or HideNetworkActivityIndicator(); from within your app (as long as the header is included of course!).

Michael Waterfall
Why not define a category on UIApplication? Seems much nicer (and more debuggable) than a #define.
Barry Wark