下载了 Xcode 7 beta,它允许用户在自己的 iOS 设备上测试他们的应用程序。我的应用程序应该从服务器流式传输音乐。
在模拟器上,我的应用程序运行良好 - 它可以在应用程序中播放,以及当我退出应用程序时。
在我的设备上,应用程序进入后台时不会播放音乐。我已经通过更改目标的功能并检查后台模式中的“音频和播放”框来完成此操作。
流代码:
stream = MPMoviePlayerController(contentURL: NSURL(string: "http://45.33.72.76:8000/stream/6/")!)
stream.view.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
stream.view.sizeToFit()
stream.movieSourceType = MPMovieSourceType.Streaming
self.view.addSubview(stream.view)
stream.fullscreen = true
stream.prepareToPlay()
stream.play()
stream.controlStyle = MPMovieControlStyle.Embedded
stream.allowsAirPlay = true
let session = AVAudioSession.sharedInstance()
do {
try session.setActive(true)
} catch {
print("ERROR")
}
有什么想法吗?
最佳答案
问题是模拟器中存在一个错误:它无法正确模拟后台模式。您尚未正确配置您的应用程序以在后台生成声音,但模拟器无法模拟这一事实。在设备上运行会发现问题。
关于ios - Xcode 7 iOS 应用程序无法在设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31015608/