How long i will run a timer in background?

旧时模样 提交于 2019-12-11 18:50:04

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/24889335/how-long-i-will-run-a-timer-in-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!