Play audio from app, even when it is in the background

后端 未结 1 1332
生来不讨喜
生来不讨喜 2021-01-21 10:53

I am having difficulties determining how I would play audio in the background for my iOS app. I have a NSTimer and wish to have a sound be played when it reaches 5 minutes, even

相关标签:
1条回答
  • 2021-01-21 11:43

    Under capabilities select the following:

    enter image description here

    In your plist make sure where it says "Application does not run in background" is NO.

    enter image description here

    Then add the following to your your appDelegate.m file.

      NSError *sessionError = nil;
    NSError *activationError = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&sessionError];
    [[AVAudioSession sharedInstance] setActive: YES error: &activationError];
    

    In the following method:

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        return YES;
    }
    
    0 讨论(0)
提交回复
热议问题