How long i will run a timer in background?

2019-08-30 02:06发布

In my application i am running a timer in background for every 8 seconds to play a custom sound,it works fine ,but it get stops at later sometime,so how can i play the sound continuously in background? Currently i am using the below code to play the sound in background

      SystemSoundID soundID;
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
        AudioServicesPlaySystemSound(soundID);

let me know the good solution to play the sound continuously in background

标签: audio ios7 timer
1条回答
闹够了就滚
2楼-- · 2019-08-30 02:32

Short answer: your app is simply suspended.

Long answer: You are missing key parts of the background savvy implementation.

  1. You need to tell the iOS that you are an Audio App, and that you are requesting extra cycles when suspended.
  2. The UIBackgroundModes is subject to approval

From the documentation:

Background modes for apps: UIBackgroundModes value = audio

The app plays audible content to the user or records audio while in the background. (This content includes streaming audio or video content using AirPlay.)

If your app does not fall into any of the categories below, then your only option to extend backgrounding beyond the typical 5 seconds is to invoke -beginBackgroundTaskWithName:expirationHandler:. You will likely be suspend within 30 seconds or so.

  • audio
  • location
  • voip
  • newsstand-content
  • external-accessory
  • bluetooth-central & bluetooth-peripheral
  • fetch
  • remote-notification
查看更多
登录 后发表回答