didFinishReceivingResourceWithName未被调用

时间:2016-01-28 01:58:50

标签: ios swift multipeer-connectivity

我在我正在制作的应用上通过MC发送视频,正确调用了didStartReceivingResourceWithName。与该回调关联的NSProgress对象达到101.0%,然后永远不会调用didFinishReceivingResourceWithName。你有什么想法?下面是每个代码。

func session(session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, withProgress progress: NSProgress) {
    print("Did start receiving resource")
    dispatch_async(dispatch_get_main_queue()){
        self.progressTimer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "progressManager", userInfo: nil, repeats: true)
        self.progress = progress
    }
}
func session(session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, atURL localURL: NSURL, withError error: NSError?) {
    dispatch_async(dispatch_get_main_queue()){
        self.status.text = "Recieved!"
    }
    self.progressTimer.invalidate()
    let destinationPath  =
    NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("movie.mov")
    let fileManager: NSFileManager = NSFileManager.defaultManager()
    do{
        try fileManager.moveItemAtURL(localURL, toURL: destinationPath)
    }
    catch let error as NSError {
        print(error)
    }
    print("Did finish receiving resource")
}

1 个答案:

答案 0 :(得分:0)

当我使用本地URL调用sendResource到我使用AVAssetWriter创建的视频文件时遇到了这个问题。原来,我是在AVAssetWriter完成视频编写之前在视频文件上调用sendResource的。在修改代码以在.finishWriting的完成处理程序中调用sendResource之后,一切按预期进行。