Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:04:33+00:00 2026-05-27T18:04:33+00:00

My application does meet the requirements for using UIBackgroundModes set to ‘App plays audio’.

  • 0

My application does meet the requirements for using UIBackgroundModes set to ‘App plays audio’. My application plays music from the MPMusicPlayerController iPodMusicPlayer class. What I’m trying to accomplish is to allow the user to set a timer for the music to stop. I’m having an issue with this. I’ve implemented the background task in the applicationDidEnterBackground method as follows:

- (void)applicationDidEnterBackground:(UIApplication *)application {
    UIDevice* device = [UIDevice currentDevice];
    BOOL backgroundSupported = NO;
    if ([device respondsToSelector:@selector(isMultitaskingSupported)]) {
        backgroundSupported = device.multitaskingSupported;
    }

    if (backgroundSupported) {
        UIApplication*    app = [UIApplication sharedApplication];
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                if (bgTask != UIBackgroundTaskInvalid) {
                    [app endBackgroundTask:bgTask];
                }
            });
        }];

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                if (bgTask != UIBackgroundTaskInvalid) {
                    if (rootController.sleepTimer != nil)
                    self.sustainTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self  selector:@selector(checkTimeRemaining) userInfo:nil repeats:YES];    
                }

            });
        });
    }
}

with the checkTimeRemaining method:

-(void)checkTimeRemaining{
    NSTimeInterval totalSeconds = rootController.timerSetInSeconds.doubleValue;
    NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate:rootController.startDateforSleepTimer];
    NSTimeInterval remainingTime = totalSeconds - elapsedTime;
    NSLog(@"remaining time %f",remainingTime);
    if (remainingTime <= 0) {
        [self.musicPlayer pause];
        [sustainTimer invalidate];
        self.sustainTimer = nil;
    }
}

I’m not getting any errors, but the timer doesn’t go beyond the allowed 10 minutes. Since I’m playing audio (along with the Background mode set) I should be able stop the music at the specified time. Any ideas on where I’m going wrong?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:04:33+00:00Added an answer on May 27, 2026 at 6:04 pm

    You can’t get it to work because the audio background modes setting allows audio processing to continue in the background until audio stops. It does not grant any special permissions to the non-audio stuff, such as BackgroundTaskWithExpirationHandler, to continue.

    But if you put time logging in an Audio Queue or RemoteIO Audio Unit buffer callback, it will keep getting called as long as audio continues to play.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that does single sign-on using a centralized authentication server (CAS).
My main application does this: It retrievs data from the internet and has 3
My Flex application does a remote call to weborb to save some data from
A function in my application does the following: Capture Web Page using Snoopy Load
When my application does EJB lookup using remote interface, I get following exception. It
I have an XML document generated from an external application, but that application does
My Application does not allow Interop.CDO to download a file from FTP server, what
Is it true: If the application does not require new features from newer APIs
If I am using spring frame work in my application does creating an object
When I run an android app from eclipse I meet this error and my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.