Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
- DispatchQueue.main.async {
- print (progress)
- }
- }
- func sendFileAction()->Progress{
- var filePath = Bundle.main.url(forResource: "10MO", withExtension: "file")
- if mcSession.connectedPeers.count > 0 {
- do {
- let data = try Data(contentsOf: filePath!)
- fileTransferProgressInSender = mcSession.sendResource(at: filePath!, withName: "filename", toPeer: mcSession.connectedPeers[0]) { (error) -> Void in
- DispatchQueue.main.async {
- if error != nil {
- print("Sending error: (String(describing: error))")
- }else{
- print("sendAFile with no error "+"filename")
- }
- }
- }
- }
- catch let error as NSError {
- let ac = UIAlertController(title: "Send file error", message: error.localizedDescription, preferredStyle: .alert)
- ac.addAction(UIAlertAction(title: "OK", style: .default))
- present(ac, animated: true)
- }
- }
- return(fileTransferProgressInSender)
- }
- <NSProgress: 0x1c0133740> : Parent: 0x0 / Fraction completed: 0.0000 / Completed: 0 of 10485760
Add Comment
Please, Sign In to add comment