从iOS应用程序向Chromecast发送本地图像时出现问题

从iOS应用程序向Chromecast发送本地图像时出现问题,ios,chromecast,Ios,Chromecast,我正在用iOS 11.4和Swift 4构建一个iOS应用程序,该应用程序将在iOS屏幕上显示本地图像库。当我从多媒体资料中选择一幅图像时,我想通过Chromecast将该图像发送到电视屏幕。 我可以连接到我的Chromecast设备,但当我尝试发送图像时,它只在电视屏幕上显示cast图标。以下是将图像传输至Chromecast的代码: PHImageManager.default().requestImage(for: asset, targetSize: targetSize, conten

我正在用iOS 11.4和Swift 4构建一个iOS应用程序,该应用程序将在iOS屏幕上显示本地图像库。当我从多媒体资料中选择一幅图像时,我想通过Chromecast将该图像发送到电视屏幕。 我可以连接到我的Chromecast设备,但当我尝试发送图像时,它只在电视屏幕上显示cast图标。以下是将图像传输至Chromecast的代码:

PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: { image, _ in

// If successful, show the image view and display the image.            
guard let image = image else { return }

// Now that we have the image, show it.
imageview.isHidden = false

// Here the image is correctly displayed on the screen
imageview.image = image

// Checking if cast session started
if self.sessionManager.hasConnectedSession() == true {

// Creating image name to save it as URL
var imageName = "Image_"

// Give image unique name
imageName = imageName + "\(self.imageNameInt)"
self.imageNameInt += 1

// Saving image to local URL so it will be compatible for use
// in GCKMediaInformation
let imageData = UIImageJPEGRepresentation(imageview.image!, 0.8)
let docDir = try! FileManager.default.url(for: .documentDirectory,
in: .userDomainMask, appropriateFor: nil, create: true)
let imageURL = docDir.appendingPathComponent(imageName)
try! imageData?.write(to: imageURL)

let metadata = GCKMediaMetadata(metadataType: .photo)
let imageAsset = imageURL.absoluteString
self.mediaInfo = GCKMediaInformation(
contentID: imageAsset,
streamType: .buffered,
contentType: "image/jpg",
metadata: metadata,
streamDuration: 0,
mediaTracks: nil,
textTrackStyle: nil,
customData: nil)

self.sessionManager.currentCastSession?.remoteMediaClient?.loadMedia(self.mediaInfo!)
}
})

每次loadMedia被称为TV时,屏幕都会刷新,但唯一显示的是cast图标。有人能检查一下这个代码,看看是否有什么错误导致图像无法发送到电视屏幕上吗?

我能够解决这个问题。为了能够将图像发送到chromecast,进而发送到电视屏幕,我必须将web服务器嵌入到我的iOS应用程序中。然后,我必须在web服务器上托管我想在电视上显示的所有图像,并将web服务器url发送到chromecast,以便chromecast能够向我的嵌入式服务器发出http请求,并将图像拉到chromecast。

请更改
内容类型:“image/jpeg”
流类型:。无
?有时我在C#上遇到同样的问题。无法从控制台应用程序向Chromecast发送本地图像。