iOS: Keep application running in background

ios background app refresh
ios prevent app from closing
call api in background ios swift
how do i find out what is running in the background on my iphone
background location update ios swift
ios background service like android
what apps are running on my iphone
how to keep apps running in the background

How do I keep my application running in the background? Would I have to jailbreak my iPhone to do this? I just need this app to check something from the internet every set interval and notify when needed, for my own use.

Yes, no need to jailbreak. Check out the "Implementing long-running background tasks" section of this doc from Apple.

From Apple's doc: Declaring Your App’s Supported Background Tasks

Support for some types of background execution must be declared in advance by the app that uses them. An app declares support for a service using its Info.plist file. Add the UIBackgroundModes key to your Info.plist file and set its value to an array containing one or more of the following strings: (see Apple's doc from link mentioned above.)

Stop Quitting iPhone Apps: It's a Waste of Time, How do I keep apps from running in the background on my iPhone? I found a way, to keep app running in background by playing silence Make sure, that you selected audio playback in background modes Also, don't use this method for long time, since it consumes CPU resources and battery juice, but I think it's a suitable way to keep app alive for a few minutes.

I guess this is what you required

When an iOS application goes to the background, are lengthy tasks paused?

iOS Application Background Downloading

This might help you ...

Enjoy Coding :)

Switch apps on your iPhone, iPad, or iPod touch, How long will an iOS app run in the background? In any case, it’s wise to check which of your iOS apps are background refresh-enabled, and to turn off the feature for any apps that (to your mind, at least) don’t need to be furiously refreshing themselves. Tap Settings > General > Background App Refresh,

Use local notifications to do that. But this will not check every time. You will have to set a time where you will check your specific event, you may shorten this by decreasing your time slot. Read more about local notification to know how to achieve this at:

How long does Apple permit a background task to run?, What does it mean if an app is running in the background? Local Notifications work great if App is foreground (or if user-interaction then also in background). Some people say ( here or here , that you will have to use "background timer" or "Packet Tunnel VPN" tricks in order to keep your app alive in background and in order to have a chance to run some callback-method eventually.

I found a way, to keep app running in background by playing silence

Make sure, that you selected audio playback in background modes

Also, don't use this method for long time, since it consumes CPU resources and battery juice, but I think it's a suitable way to keep app alive for a few minutes.

Just create an instance of SilencePlayer, call play() and then stop(), when you done

import CoreAudio

public class SilencePlayer {
    private var audioQueue: AudioQueueRef? = nil
    public private(set) var isStarted = false

    public func play() {
        if isStarted { return }
        print("Playing silence")
        let avs = AVAudioSession.sharedInstance()
        try! avs.setCategory(AVAudioSessionCategoryPlayback, with: .mixWithOthers)
        try! avs.setActive(true)
        isStarted = true
        var streamFormat = AudioStreamBasicDescription(
            mSampleRate: 16000,
            mFormatID: kAudioFormatLinearPCM,
            mFormatFlags: kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked,
            mBytesPerPacket: 2,
            mFramesPerPacket: 1,
            mBytesPerFrame: 2,
            mChannelsPerFrame: 1,
            mBitsPerChannel: 16,
            mReserved: 0
        let status = AudioQueueNewOutput(
            nil, nil, nil, 0,
        print("OSStatus for silence \(status)")
        var buffers = Array<AudioQueueBufferRef?>.init(repeating: nil, count: 3)
        for i in 0..<3 {
            buffers[i]?.pointee.mAudioDataByteSize = 320
            AudioQueueAllocateBuffer(audioQueue!, 320, &(buffers[i]))
            SilenceQueueOutputCallback(nil, audioQueue!, buffers[i]!)
        let startStatus = AudioQueueStart(audioQueue!, nil)
        print("Start status for silence \(startStatus)")

    public func stop() {
        guard isStarted else { return }
        print("Called stop silence")
        if let aq = audioQueue {
            AudioQueueStop(aq, true)
            audioQueue = nil
        try! AVAudioSession.sharedInstance().setActive(false)
        isStarted = false


fileprivate func SilenceQueueOutputCallback(_ userData: UnsafeMutableRawPointer?, _ audioQueueRef: AudioQueueRef, _ bufferRef: AudioQueueBufferRef) -> Void {
    let pointer = bufferRef.pointee.mAudioData
    let length = bufferRef.pointee.mAudioDataByteSize
    memset(pointer, 0, Int(length))
    if AudioQueueEnqueueBuffer(audioQueueRef, bufferRef, 0, nil) != 0 {
        AudioQueueFreeBuffer(audioQueueRef, bufferRef)

Tested on iOS 10 and Swift 4

What does it mean for the app to 'run in the background'? – XY, Yes, no need to jailbreak. Check out the "Implementing long-running background tasks" section of this doc from Apple. From Apple's doc:  This tweak forwards your notifications to your PC (Mac and Linux only for now) or iOS device (tested on iOS 9-13 for the receiver part) It works using SSH, so it can works locally for now (although I will add more features in the future for it to work via open ports and use other services like PushOver).

I know this is not the answer to your question, but I think it is a solution.

This assumes that your trying to check something or get data from the internet on a regular basis?

Create a service that checks the internet every set interval for whatever it is you want to know, and create a push notification to alert you of it, if the server is down, or whatever it is your trying to monitor has changed state. Just an idea.

iOS: Keep application running in background, It's not possible to run an app in the background as if it was in the foreground. Apps can only run a limited set of tasks in the background for a short period of time per Apple guidelines, or use structured backgrounding such as Background App Refresh. location—The app keeps users informed of their location, even while it is running in the background. voip—The app provides the ability for the user to make phone calls using an Internet connection. newsstand-content—The app is aNewsstand app that downloads and processesmagazine or newspaper content in the background.

How can I keep an app open in the background?, When the user exits a foreground app, that app moves to the background state briefly before UIKit In iOS 12 and earlier—The UIApplicationDelegate object. It wants the company to remove the operating system block and allow its app's Bluetooth functionality to run constantly in the background.

Preparing Your UI to Run in the Background, Hello Friends,. I am fetching one big issue regarding keep app live in background forever. Can anybody help to resolve my below issue. Issue:. Your app is only allowed to keep running in the background in very specific cases. For example, these include playing audio, getting location updates or fetching the latest content from a server. If your task does not fall into these categories, backgrounding may not be for you.

How to Keep Your iOS App Running in Backg…, Apple's iOS 13 has a rocky road since its mid-September launch. Other popular app makers and software developers have chimed in as well: and Overcast users keep reporting it as well: background apps seem to be getting Keeper” keeps a running GPS-based log of where you connect to servers. Registering Xamarin.iOS Apps to Run in the Background. 03/18/2017; 2 minutes to read; In this article. Registering individual tasks for background privileges works for some applications, but what happens if an application is constantly called upon to perform important, long-running tasks, such as getting directions for the user via GPS?

  • Hi Denis hope you have got your answer. If yes, then can you please mark your respective answer as true and up vote as well...
  • @takrishna, If you are writing this app for your own use, then set UIBackgroundModes value "voip" (Voice over IP). That is the easiest type of app to keep alive forever in background. (But don't submit it to app store, unless it really is a VOIP app.)
  • For an app store app, if you don't have a server to periodically send "Remote notifications" to your phone, your only other option is "Background fetch".
  • No, if the app is in background, all that a local notification will do is show that notification to the user. You can't do any actual work unless the user clicks on the notification to bring the app to foreground.
  • Thank you for sharing this.
  • :- How much time silence player plays sound?
  • @YogeshRaut it plays silence until you call stop()
  • @DimaRostopira I'm doing something similar to this but notice my app still gets quit after a few hours. My code does use AVAudioPlayer mind rather than audio queues like yours, how long have you seen this successfully keep your app running for?
  • @simonthumper I'm using this only for 3 minutes, I don't need more than that
  • I thought the app will automatically be terminated after some duration, will it not? Pardon my ignorance if I'm wrong. I'm very new to iOS programming.
  • unless iOS needs that memory for another app, it won't be, and as long as you are doing something in the background
  • No. Applications cannot run in the background for over 10 minutes, except for a few certain situations (VOIP, playing audio, etc.)