开发者

Using NSTimer to shutdown app

Bit of a noob here.

I am developing an app that plays some looped sounds. I would like to give the user the 开发者_运维知识库ability to shut down the app after a certain amount of time using a timer. The idea is the user presses a button and the app will shut down once the timer runs out.

At the moment if the button is pressed, the app crashes.

Here's what I got so far:

- (IBAction)timer:(id)sender{

    timer = [NSTimer scheduledTimerWithInterval: 10.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];

}


-(void) targetMethod: (NSTimer*) theTimer {
    NSLog(@"timer?");
    exit(0);

}


You need to properly define your timer reference:

NSTimer *timer = [NSTimer scheduledTimerWithInterval: 10.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜