feat(*): add sender to files pack result
This commit is contained in:
@@ -6,30 +6,29 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MultipeerConnectivity
|
||||
|
||||
|
||||
class NearbyStartCommand {
|
||||
|
||||
init( id: String, filesCount: Int) {
|
||||
self.id = id
|
||||
init(senderName: String, filesCount: Int) {
|
||||
self.senderName = senderName
|
||||
self.filesCount = filesCount
|
||||
}
|
||||
|
||||
static func fromUserInfo(userInfo: NearbyUserInfo)-> NearbyStartCommand? {
|
||||
if let id = userInfo.dictionary["id"] as? String ,
|
||||
if let name = userInfo.dictionary["name"] as? String,
|
||||
let filesCount = userInfo.dictionary["filesCount"] as? Int
|
||||
{
|
||||
return NearbyStartCommand(
|
||||
id: id, filesCount: filesCount
|
||||
)
|
||||
return NearbyStartCommand(senderName: name, filesCount: filesCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func toDictionary() -> [String: Any] {
|
||||
return ["id": id, "filesCount": filesCount]
|
||||
return ["name": senderName, "filesCount": filesCount]
|
||||
}
|
||||
|
||||
let id: String
|
||||
let senderName: String
|
||||
let filesCount: Int
|
||||
}
|
||||
|
||||
@@ -47,15 +47,17 @@ extension NearbySession: MCSessionDelegate {
|
||||
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) {
|
||||
guard let localURL = localURL else { return }
|
||||
|
||||
let destinationURL = localURL.deletingLastPathComponent().appendingPathComponent("\(resourceName)")
|
||||
var destinationURL = localURL.deletingLastPathComponent().appendingPathComponent("\(resourceName)")
|
||||
|
||||
if FileManager.default.fileExists(atPath: destinationURL.path) {
|
||||
destinationURL = localURL.deletingLastPathComponent().appendingPathComponent("New_\(resourceName)")
|
||||
}
|
||||
|
||||
do {
|
||||
try FileManager.default.moveItem(at: localURL, to: destinationURL)
|
||||
} catch {
|
||||
Logger.error(message: "Error moving file: \(error)")
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(
|
||||
name: ON_RESOURCE_RECEIVED,
|
||||
object: nil,
|
||||
|
||||
Reference in New Issue
Block a user