有人知道如何从CarPlay的列表视图中删除小云图标吗?我包括了它的屏幕截图。这些电台只能进行直播,不能下载。我还将代码包括到我的Carplay-AppDelegate,CarPlay-Playlist和CarPlay-StationList中。谢谢
CARPLAY-APPDELEGATE代码:
import Foundation
import MediaPlayer
extension AppDelegate {
func setupCarPlay() {
playableContentManager = MPPlayableContentManager.shared()
playableContentManager?.delegate = self
playableContentManager?.dataSource = self
stationsViewController?.setupRemoteCommandCenter()
stationsViewController?.updateLockScreen(with: nil)
}
}
extension AppDelegate: MPPlayableContentDelegate {
func playableContentManager(_ contentManager: MPPlayableContentManager, initiatePlaybackOfContentItemAt indexPath: IndexPath, completionHandler: @escaping (Error?) -> Void) {
DispatchQueue.main.async {
UIApplication.shared.beginReceivingRemoteControlEvents()
if indexPath.count == 2 {
let station = self.carplayPlaylist.stations[indexPath[1]]
self.stationsViewController?.selectFromCarPlay(station)
}
completionHandler(nil)
// Workaround to make the Now Playing working on the simulator:
// Source: https://stackoverflow.com/questions/52818170/handling-playback-events-in-carplay-with-mpnowplayinginfocenter
// UIApplication.shared.endReceivingRemoteControlEvents()
// UIApplication.shared.beginReceivingRemoteControlEvents()
}
}
func beginLoadingChildItems(at indexPath: IndexPath, completionHandler: @escaping (Error?) -> Void) {
carplayPlaylist.load { error in
completionHandler(error)
}
}
}
extension AppDelegate: MPPlayableContentDataSource {
func numberOfChildItems(at indexPath: IndexPath) -> Int {
if indexPath.indices.count == 0 {
return 1
}
return carplayPlaylist.stations.count
}
func contentItem(at indexPath: IndexPath) -> MPContentItem? {
if indexPath.count == 1 {
// Tab section
let item = MPContentItem(identifier: "Stations")
item.title = "Stations"
item.isContainer = true
item.isPlayable = false
item.artwork = MPMediaItemArtwork(boundsSize: #imageLiteral(resourceName: "carPlayTab").size, requestHandler: { _ -> UIImage in
return #imageLiteral(resourceName: "carPlayTab")
})
return item
} else if indexPath.count == 2, indexPath.item < carplayPlaylist.stations.count {
// Stations section
let station = carplayPlaylist.stations[indexPath.item]
let item = MPContentItem(identifier: "\(station.name)")
item.title = station.name
item.subtitle = station.desc
item.isPlayable = true
item.isStreamingContent = true
if station.imageURL.contains("http") {
ImageLoader.sharedLoader.imageForUrl(urlString: station.imageURL) { image, _ in
DispatchQueue.main.async {
guard let image = image else { return }
item.artwork = MPMediaItemArtwork(boundsSize: image.size, requestHandler: { _ -> UIImage in
return image
})
}
}
} else {
if let image = UIImage(named: station.imageURL) ?? UIImage(named: "stationImage") {
item.artwork = MPMediaItemArtwork(boundsSize: image.size, requestHandler: { _ -> UIImage in
return image
})
}
}
return item
} else {
return nil
}
}
}
CARPLAY-PLAYLIST代码:
import Foundation
class CarPlayPlaylist {
var stations = [RadioStation]()
func load(_ completion: @escaping (Error?) -> Void) {
DataManager.getStationDataWithSuccess() { (data) in
guard let data = data else {
completion(nil)
return
}
do {
let jsonDictionary = try JSONDecoder().decode([String: [RadioStation]].self, from: data)
if let stationsArray = jsonDictionary["station"] {
self.stations = stationsArray
}
} catch (let error) {
completion(error)
return
}
completion(nil)
}
}
}
CARPLAY-STATIONLIST代码:
import UIKit
extension StationsViewController {
func selectFromCarPlay(_ station: RadioStation) {
radioPlayer.station = station
handleRemoteStationChange()
}
}
答案 0 :(得分:1)
云图标的存在取决于isStreamingContent
的值。