0

我想改进我的 App FM-Pod与 Siri 意图快捷方式的集成。我已经完成了这个应用程序来收听 HomePod 上的广播,到目前为止,我已经能够开始播放、更改电台等,但我遇到了一个奇怪的问题,导致音频播放停止大约1分钟后独自...

有谁知道原因?怎么了?

下面是使用 AVAudioPlayer 开始播放的 Swift 代码:

open func handle(intent: StartFMPodIntent, completion: @escaping (StartFMPodIntentResponse) -> Void) {

    DataManager.getStationDataWithSuccess(filename: "favorites") { (data) in
        if debug { print("Stations JSON Found") }
        guard let data = data, let jsonDictionary = try? JSONDecoder().decode([String: [RadioStation]].self, from: data), let stationsArray = jsonDictionary["station"]
            else {
                if debug { print("JSON Station Loading Error") }
                return
        }
            HPRIntentHandler.stations = stationsArray
            if !FRadioPlayer.shared.isPlaying {
                FRadioPlayer.shared.radioURL = URL(string: HPRIntentHandler.stations![0].streamURL0!)
                let response = StartFMPodIntentResponse(code: .success, userActivity: nil)
                response.stationName = stationsArray[0].name
                completion(response)
            }


    }
}
4

1 回答 1

0

根据https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionOverview.html#//apple_ref/doc/uid/TP40014214-CH2-SW2

代码完成运行后,扩展被终止。由于 getStationDataWithSuccess 以异步方式运行,因此它的代码在异步函数完成运行之前就已经结束。你必须找到不同的地方来处理这个问题。

于 2018-11-02T14:28:10.763 回答