这是我的代码,我使用uiwebview加载网页并听音乐,但是当按下主页按钮时,音乐停止。我怎样才能在背景中继续工作。
这是我的代码。
var webView: UIWebView!
override func viewWillAppear(_ animated: Bool) {
navigationItem.title = "Desdeelcanton.com"
view.backgroundColor = UIColor.white
}
override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
webView = UIWebView(frame: UIScreen.main.bounds)
webView.delegate = self
view.addSubview(webView)
if let url = URL(string: "http://desdeelcanton.com") {
let request = URLRequest(url: url)
webView.loadRequest(request)
}
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(appMovedToBackground), name: Notification.Name.UIApplicationWillResignActive, object: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func appMovedToBackground() {
print("App moved to background!")
}