gpt4 book ai didi

ios - 无法将类型 'NSURL.Type' 的值转换为预期的参数类型 'NSURL?'

转载 作者:行者123 更新时间:2023-11-28 06:37:28 26 4
gpt4 key购买 nike

我正在尝试使用 swiftfirebase 构建聊天应用程序并收到此错误:下面是代码:我仍然不明白哪里出了问题!!我也在使用 JSQMessageViewController

func sendMedia(picture: UIImage?, video: NSURL?) {
print(picture)
print(FIRStorage.storage().reference())
if let picture = picture {
let filePath = "\(FIRAuth.auth()!.currentUser?.uid)/\(NSDate.timeIntervalSinceReferenceDate())"
print(filePath)
let data = UIImageJPEGRepresentation(picture, 0.1)
let metadata = FIRStorageMetadata()
metadata.contentType = "image/jpg"
FIRStorage.storage().reference().child(filePath).putData(data!, metadata: metadata) { (metadata, error) in
if error != nil {
print(error?.localizedDescription)
return
}
let fileUrl = metadata!.downloadURLs![0].absoluteString
let newMessage = self.messageRef.childByAutoId()
let messageData = ["fileUrl": fileUrl, "senderId": self.senderId, "senderName": self.senderDisplayName, "MediaType": "PHOTO"]
newMessage.setValue(messageData)
}
}else if let video = video {
let filePath = "\(FIRAuth.auth()!.currentUser?.uid)/\(NSDate.timeIntervalSinceReferenceDate())"
print(filePath)
let data = NSData(contentsOfURL: video)
let metadata = FIRStorageMetadata()
metadata.contentType = "video/mp4"
FIRStorage.storage().reference().child(filePath).putData(data!, metadata: metadata) { (metadata, error) in
if error != nil {
print(error?.localizedDescription)
return
}
let fileUrl = metadata!.downloadURLs![0].absoluteString
let newMessage = self.messageRef.childByAutoId()
let messageData = ["fileUrl": fileUrl, "senderId": self.senderId, "senderName": self.senderDisplayName, "MediaType": "VIDEO"]
newMessage.setValue(messageData)
}

}
}

}

extension ChatViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
print("Did finish picking")
//get the image
print(info)
if let picture = info[UIImagePickerControllerOriginalImage] as? UIImage {
let photo = JSQPhotoMediaItem(image: picture)
messages.append(JSQMessage(senderId: senderId, displayName: senderDisplayName, media: photo))
sendMedia(picture, video: nil)
}
else if let video = info[UIImagePickerControllerMediaURL] as? NSURL {
let videoItem = JSQVideoMediaItem(fileURL: video, isReadyToPlay: true)
messages.append(JSQMessage(senderId: senderId, displayName: senderDisplayName, media: videoItem))
sendMedia(nil, video: NSURL)
}
self.dismissViewControllerAnimated(true, completion: nil)
collectionView.reloadData()
}
}

如果错误与 NSURl 类型有关,我不知道如何修复它。

最佳答案

在这一行中:

sendMedia(nil, video: NSURL)

您正在将 NSURL 作为第二个参数 video 传递。(记住 video: 只是一个参数标签。)

也许你需要把它写成:

sendMedia(nil, video: video)

关于ios - 无法将类型 'NSURL.Type' 的值转换为预期的参数类型 'NSURL?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807262/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com