PhotosPicker(selection: $selectedItem, matching: .videos){
Image(systemName: "camera.fill")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 20)
.padding(2)
}
.onChange(of: selectedItem) { newItem in
videoURL = nil
Task {
if let data = try? await newItem?.loadTransferable(type: Data.self) {
let bytes = Double(data.count)
let megabytes = bytes / (8 * 1024 * 1024)
print("size:")
print(megabytes)
if(megabytes > 32){
print("too big")
}else{
let tempFile = TemporaryMediaFile(withData: data)
let asset = tempFile.avAsset
let vidWidth = await asset?.naturalSize()?.width
let vidHeight = await asset?.naturalSize()?.height
videoHeight = 160 * (vidHeight! / vidWidth!)
videoURL = tempFile.url
}
}else{
print("picking failed")
}
}
}
我明白了
如果“任务”上没有类型注释,则表达式类型不明确
如何修复?
将您的代码更改为: