iPhone UIActivityIndicator not working at first launch - iphone

It works fine on every subsequent launches. I'm using an OpenGL animation at the start, if it matters.

The activity indicator is hidden and inactive by default.
Call [activityIndicator startAnimating] to start it manually.
Good luck!

Related

Custom Activity Indicator Issue

I am making an iPhone app in which I have made a custom activity indicator class to show an activity indicator animating on another class, but my problem is that the activity indicator class get start animating but it doesn't get stop animating.
Here is the code:
customActivityView = [[ CustomActivityIndicatorView alloc] init];
customActivityView.view.center = self.view.center;
[self.view addSubview:customActivityView.view];
[customActivityView.activityIndicator startAnimating]; // is work fine to add a custom activity indicator and start animating
[customActivityView.activityIndicator stopAnimating]; // but this line doesn't work
Check that customActivityView.activityIndicator actually returns the activity view, or quite likely, if it returns anything at all.
You cannot start and stop an activity indicator in the same method.if you do so you cannot see anythng in result.
Sorry it's working now actually my custom Activity class was get assign two times that why it didn't stop.

Setting MPMoviePlayer controlStyle to MPMovieControlStyleNone crashes app

I have an app which uses a manager to offer up the relevant custom view for a selected item when selected.
The selection is done through one of 3 parent custom views
TableView
PageControl
Gallery (essentially another TableView)
One of the custom views displays a view with an embedded MPMovieControl on it.
This works fine however for some reason in the Gallery view if I have set the controlStyle of the video set to MPControlStyleNone the app crashes, well it locks up the simulator and Xcodes debugger doesnt even notice, just assumes its still running.
This line is the culprit
player.controlStyle = MPMovieControlStyleNone;
Without it, it works fine, but then I obviously have the unrequired controls displayed
iOS 2.0 through iOS 3.1 uses movieControlMode. Everything newer uses controlStyle. Test for newer and fall back to older.
if ([movie respondsToSelector:#selector(setControlStyle:)]) {
movie.controlStyle = MPMovieControlStyleNone;
} else {
movie.movieControlMode = MPMovieControlModeHidden;
}
May be this will work.
[player setControlStyle:MPMovieControlStyleNone];
Run the program using the profiler and check for NSZombies. Most likely the app is crashing due to a wrong release count or an autorelease and the symptom is your movie crashing when it might be something related to you starting the movie and needing it later to find it was released.

Dynamically calculate application load time

How can I run a clock that allows me to measure the time to load until appDidFinishLaunching ?
I want to set a sleep call that extends the Defaul.png show time to 3 seconds regardless the speed of the underlying hardware.
First off, you should know that Springboard in iPhone OS is kinda picky about load times. You should never make a sleep call somewhere in the loading process of you application. If Springboard detects that your application is taking too long to launch, your application will be terminated with "failed to launch in time" in the crash log.
Secondly, there is no, as far as I know, way of measuring the time your application took to launch. There are several thing happening when the user taps the Application icon on the springboard, and the iPhone OS provides no good information to your application.
One solution could be to make sure your applicationDidFinishLaunching: is very lightweight, and creating a "fake" Default.png overlay. By trimming down your applicationDidFinishLaunching: method to do only the most essential stuff, and the performing any time consuming tasks in the background, you can ensure that your Default.png overlay is displayed roughly the same time on different hardware.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Create the image view posing with default.png on top of the application
UIImageView *defaultPNG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]];
// Add the image view top-most in the window
[window addSubview:defaultPNG];
[window makeKeyAndVisible];
// Begin doing the time consuming stuff in the background
[self performSelectorInBackground:#selector(loadStuff) withObject:nil];
// Remove the default.png after 3 seconds
[self performSelector:#selector(removeDefaultPNG:) withObject:defaultPNG afterDelay:3.0f];
}
- (void)removeDefaultPNG:(UIImageView *)defaultPNG {
// We're now assuming that the application is loaded underneath the defaultPNG overlay
// This might not be the case, so you can also check here to see if it's ok to remove the overlay
[defaultPNG removeFromSuperview];
[defaultPNG release];
}
If you add more views (your view controllers etc) in the loadStuff method, you should insert them below the defaultPNG overlay. You should also be aware of problems that could occur by doing these things from another thread. You could use performSelectorOnMainThread:withObject:waitUntilDone: if you encounter problems.

How to delay Default.png?

How can I delay the app loading to show the splash screen for longer?
You should let the app start as usual then make the first view that appears have the identical image on it as the splash screen. Start a timer and then replace that view with your real application root view after a few seconds.
Deliberately delaying the actual application launch is a big no-no.
UPDATE: No seriously, DON'T do this!
Or us the C function
sleep(9);
Putting this in applicationDidFinishLaunching: will cause you program to pause for 9 seconds, any other integer may be entered as well.
EDIT: I've learned a lot in the past year. Don't do this. The reason being that the springboard will automatically stop the app launching if it takes too long. That timing is poorly documented so even one second can result in the app failing.
This question is similar: splash screen like tap tap revenge 3
Basically, in your applicationDidFinishLaunching:, add an image view on top of other views containing your Default.png.
See the above discussion of why you probably should not delay your app load in this way. But if you happen to have a scenario where sleeping for short duration would be preferable to the overhead of switching out a view, use NSThread's sleepForTimeIntervale instead of sleep(). It's more framework friendly and you have more granular control over the sleep time:
[NSThread sleepForTimeInterval:0.75]
I had a situation where the client had to demo the launch image. So, this was my solution..
- (void)applicationDidBecomeActive:(UIApplication *)application
{
UIImageView *defaultImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default#2x.png"]];
[self.window addSubview:defaultImageView];
sleep(2);
[defaultImageView removeFromSuperview];
[defaultImageView release];
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
You can use it sleep method to get this result "
sleepForTimeInterval
", If you want to get it launch time, do like :
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
[NSThread sleepForTimeInterval:8.0];
}
It will delay the launch by 8 seconds
Warning : But it is not recommended by apple, as it will the watchdod about long time for your app loading, It can kill your app.
But incase if you need it to get some specific screenshot or for some in-house use, you can use to solve for purpose but never in app submission.

Iphone Invisible Keyboard

I'm working on an app right now that was working fine until I started implementing some threading for background loading of images. Now theres no crashes but the keyboard does not display. That is to say its invisible (I can still type, I just cant see the actual keyboard).
The only thing I've done was implement threading so I'm wondering if I'm somehow messing with the thread the keyboard runs on or something?
The threads I'm calling are like:
[NSThread detachNewThreadSelector:#selector(loadWebView:)
toTarget:self withObject:[NSNumber numberWithInt:pageNum]];
and
[scrollView performSelectorOnMainThread:#selector(addSubview:)
withObject:curWebView waitUntilDone:NO];
Thanks in advance.
UIWebViews (and all UI elements) cannot be used on background threads safely. If you wish to load images in the background, use NSURLConnection's asynchronous loading methods.