Domanda

is their any better way to quit the application programmatically?

recently i made a radio application that have a user setup to set a time using NSTimer for quit the app process ( i mean sleep time). when the time reaches the app should be stop its process and quit.

i used these statements to quit the app when time reaches,

  [[UIApplication sharedApplication] suspend];
  [[UIApplication sharedApplication] terminateWithSuccess];

theTimer=[NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(countTime) userInfo:nil repeats:YES];

counter-=1;
timeLeft.text=[NSString stringWithFormat:@" %d",counter];
if (counter==0.0) {

    [theTimer invalidate];
  [[UIApplication sharedApplication] suspend];
  [[UIApplication sharedApplication] terminateWithSuccess];

is their any problem by using [[UIApplication sharedApplication] suspend]; [[UIApplication sharedApplication] terminateWithSuccess]; methods

any other better way to quit the app, or at least freeze the app process.. i need help?

È stato utile?

Soluzione

I've always used exit(0). I suppose that if you have to run code before the app quitting you should call it before exit(0).

Apple discourages the use of exit() because from the user point of view it looks like a crash. But they also say there is no API call to gracefully terminate your app.

If you're looking for a way to terminate your app without the user pressing home, during sleep time, I assume he won't confuse it with a crash, since he won't be paying attention to your app and exit() leaves no crash log.

So, your options are:

  • Forget this and just beep after some time to remind him to close the app. (terrible!)
  • Close the app using your private calls and risk Apple's rejection.
  • Close the app using exit() and stick with POSIX (accepted) calls.

Altri suggerimenti

Apple will not approve any application that deliberately suspends or terminates itself. You may use only those methods listed in the official documentation, which does not include suspend or terminateWithSuccess.

tanq for your replays, so i just forget about quitting my application programatically. next way is to stop playing my MPMoviePlayerController object. got the next level problem

my settings page for sleepTime and music playing pages, both are different viewControllers so i can't access MPMoviePlayerController object directly in time settings page, so i created a method on music playing page

MPMoviePlayerController *player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@"http://www.radioparadise.com/musiclinks/rp_64aac.m3u"]];
[player prepareToPlay];
[player play];

- (IBAction)StopPlay:(id)sender 
{   
 [player stop];
}

so i created an object for music playing page and i called this method from settings page., this is my code in settingsPage

@class MusicPlayingPage;
 @interface secondView : UIViewController
{
MusicPlayingPage *audio; 
}

and called the method in settingsPage

[audio stopPlay];

control reaches correctly to streamingPage, but it seems like player is not stoping play, i can't access any of these player options [player stop]; , [player pause];

any problem for this method in musicPlayingPage

- (IBAction)StopPlay:(id)sender 
{   
 [player stop];
}

sorry if my question is not understandable.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top