Guest User

Untitled

a guest
Mar 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
  2. DispatchQueue.main.async {
  3. print (progress)
  4. }
  5. }
  6.  
  7. func sendFileAction()->Progress{
  8. var filePath = Bundle.main.url(forResource: "10MO", withExtension: "file")
  9. if mcSession.connectedPeers.count > 0 {
  10.  
  11. do {
  12. let data = try Data(contentsOf: filePath!)
  13. fileTransferProgressInSender = mcSession.sendResource(at: filePath!, withName: "filename", toPeer: mcSession.connectedPeers[0]) { (error) -> Void in
  14. DispatchQueue.main.async {
  15. if error != nil {
  16. print("Sending error: (String(describing: error))")
  17. }else{
  18. print("sendAFile with no error "+"filename")
  19. }
  20. }
  21. }
  22. }
  23. catch let error as NSError {
  24. let ac = UIAlertController(title: "Send file error", message: error.localizedDescription, preferredStyle: .alert)
  25. ac.addAction(UIAlertAction(title: "OK", style: .default))
  26. present(ac, animated: true)
  27. }
  28. }
  29. return(fileTransferProgressInSender)
  30. }
  31.  
  32. <NSProgress: 0x1c0133740> : Parent: 0x0 / Fraction completed: 0.0000 / Completed: 0 of 10485760
Add Comment
Please, Sign In to add comment