如何在后台运行iOS应用以解析大量数据API?

问题描述 投票:0回答:1

我有一个应用程序,它在后台模式下工作,音乐在后台模式下播放,在播放音乐背景时,我们调用API并将10,000条记录数据解析到本地db中。但它没有发生,似乎应用程序在后台崩溃了。

任何建议,我们都欢迎,如果我们没有点击任何API,并且音乐正在后台播放,但是当API解析发生时,音乐和应用程序将停止。

guard let bundle = Bundle.main.path(forResource:“ bird”,ofType:“ wav”)else {return}

        let alertSound = URL(fileURLWithPath: bundle)
        //try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.moviePlayback, options: AVAudioSession.CategoryOptions.mixWithOthers)
        try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: AVAudioSession.Mode.moviePlayback, policy: AVAudioSession.RouteSharingPolicy.default, options: AVAudioSession.CategoryOptions.mixWithOthers)
        //try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
        try AVAudioSession.sharedInstance().setActive(true)
        try self.player = AVAudioPlayer(contentsOf: alertSound)
        // Play audio forever by setting num of loops to -1
        self.player?.numberOfLoops = -1
        self.player?.volume = 0.01
        self.player?.prepareToPlay()
        self.player?.play()
ios swift background avaudioplayer
1个回答
0
投票

您可以在后台模式下做的事情非常有限。您可以使用后台应用刷新执行受限任务apple docs for app refreshapp background lifecycle method。有关后台应用程序刷新的在线资源非常丰富。如果用户禁用了应用程序的后台应用程序刷新,即使这样也无法正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.