On iOS 11, I can not send a file of light size using Multipeer Connectivity.
However, on iOS 10, it was able to send regardless of size.
If it could not be sent, the block in "completionHandler" of "MCSession.sendResource (at: withName: toPeer: withCompletionHandler :)" was not called.
(On the receiving side, "session(_:didFinishReceivingResourceWithName:fromPeer:at:withError:)" of "MCSessionDelegate" was not called.)
Probably, when the size is light, processing of the transmission status seems not functioning properly.
Even iOS 11, It was able to receive a file of light size.
What do I need to send a file of light size on iOS 11?
Error Image
Programing
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
}
}