How to run NSTimer in background and sleep in iOS?

后端 未结 6 625
南笙
南笙 2021-02-04 21:56

I found a lot of post in stackoverflow about NSTimer run in background.

However I didn\'t find any solution.

In my app , I play sound in background

6条回答
  •  不知归路
    2021-02-04 22:42

    // NSTimer run when app in background 
    [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil]; loop = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(Update) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:loop forMode:NSRunLoopCommonModes];

    This is what do you want?.

提交回复
热议问题