0

iOS 11上,我无法使用 Multipeer Connectivity发送轻量级文件。
但是,在iOS 10上,无论大小如何,它都可以发送。

如果无法发送,则“MCSession.sendResource (at: withName: toPeer: withCompletionHandler :)”的“completionHandler”中的块没有被调用。
(在接收方,“MCSessionDelegate”的“session(_:didFinishReceivingResourceWithName:fromPeer:at:withError:)”没有被调用。)
可能,当大小较轻时,传输状态的处理似乎无法正常工作。

即使是 iOS 11,它也能接收到一个轻量级的文件。

在 iOS 11 上发送轻量级文件需要什么?

错误图像

MultipeerConnectivity 错误图像

编程

import MultipeerConnectivity

class SessionContainer: NSObject, MCSessionDelegate {
    var session:MCSession?
    var delegate:SessionContainerDelegate?

    func sendImage(imageUrl:URL) -> Transcript {

        var progress:Progress?
        // Loop on connected peers and send the image to each
        for peerID in (self.session?.connectedPeers)! {
            progress = self.session?.sendResource(at: imageUrl, withName: imageUrl.lastPathComponent, toPeer: peerID, withCompletionHandler: { (error) in

                // **WAS NOT CALLED!!!**
                if (error != nil) {
                    print("Send resource to peer " + peerID.displayName + " completed with Error " + error.debugDescription)
                } else {
                    // Create an image transcript for this received image resource
                    let transcript:Transcript = Transcript().initWithPeerID(peerID: (self.session?.myPeerID)!, imageUrl: imageUrl, direction: .TRANSCRIPT_DIRECTION_SEND)
                    self.delegate?.updateTranscript(transcript: transcript)
                }
                // **WAS NOT CALLED!!!**

            })

        }
        // Create an outgoing progress transcript.  For simplicity we will monitor a single NSProgress.  However users can measure each NSProgress returned individually as needed
        let transcript:Transcript = Transcript().initWithPeerID(peerID: (self.session?.myPeerID)!, imageName: imageUrl.lastPathComponent, progress: progress, direction: .TRANSCRIPT_DIRECTION_SEND)

        return transcript
    }
}

https://github.com/amarron1/MultipeerGroupChatSwift/blob/master/MultipeerGroupChatSwift/SessionContainer.swift

参考

4

0 回答 0