【发布时间】:2017-11-16 11:07:13
【问题描述】:
我是响应式编程的新手,我有一个无法单独解决的大问题...我需要按顺序上传几个视频资产,但我不知道该怎么做,我有一组PHAssets,我正在尝试遍历每个元素并通过网络发送它 到目前为止,这是我使用 cmets 的代码:
for item in items {
let fileName = item.media.localIdentifier
//Observable to generate local url to be used to save the compressed video
let compressedVideoOutputUrl = videoHelper.getDocumentsURL().appendingPathComponent(fileName)
//Observable to generate a thumbnail image for the video
let thumbnailObservable = videoHelper.getBase64Thumbnail(myItem: item)
//Observable to request the video from the iPhone library
let videoObservable = videoHelper.requestVideo(myItem: item)
//Compress the video and save it on the previously generated local url
.flatMap { videoHelper.compressVideo(inputURL: $0, outputURL: compressedVideoOutputUrl) }
//Generate the thumbnail and share the video to send over the network
let send = videoObservable.flatMap { _ in thumbnailObservable }
.flatMap { api.uploadSharedFiles(item, filename: fileName, base64String: $0) }
//subscribe the observable
send.subscribe(onNext: { data in
print("- Done chain sharing Video -")
},
onError: { error in
print("Error sharing Video-> \(error.localizedDescription)")
}).disposed(by: actionDisposeBag)
}
【问题讨论】:
标签: ios swift reactive-programming rx-swift