Local Sync is a framework created for transfering the data locally, using Multipeer Connectivity.
The communication only happen between different types of devices, masters and slaves. In other words, masters can only transfer and receive data from slaves, and slaves can only transfer and receive data from masters.
To become a master, that is be able to transfer and send data to slaves, you need to do the steps above.
- Import LocalSync:
import LocalSync
- Implement the Procotol
LCMasterFacadeDelegate
:
It is through this method that you will receive the data from slaves.
class YourClass: LCMasterFacadeDelegate {
func didReceiveData(_ data: Data, fromPeer peerID: MCPeerID) {
// Handle the data that you received from slaves
}
}
- Create a master sync variable:
It is through this variable that you will send the data to slaves.
let masterSync = LCMasterFacade()
masterSync.delegate = yourClassThatImplementedLCMasterFacadeDelegate
To become a slave, that is be able to transfer and send data to masters, you need to do the steps above.
- Import LocalSync:
import LocalSync
- Implement the Procotol
LCSlaveFacadeDelegate
:
It is through this method that you will receive the data from masters.
class YourClass: LCSlaveFacadeDelegate {
func didReceiveData(_ data: Data, fromPeer peerID: MCPeerID) {
// Handle the data that you received from masters
}
}
- Create a slave sync variable:
It is through this variable that you will send the data to masters.
let slaveSync = LCSlaveFacade()
slaveSync.delegate = yourClassThatImplementedLCSlaveFacadeDelegate
- Removing the identifier from master/slave names:
The framework uses the display name of the MCPeerID
to identify masters and slaves. So the display name have a UUID attached to it. So if you want to show the name of the peerID that have sended you the data, it's a good practice to remove this UUID, by doing the following
// Removing the slave UUID
peerID.displayName.replacingOccurrences(of: LCConstants.slave, with: "")
// Removing the master UUID
peerID.displayName.replacingOccurrences(of: LCConstants.master, with: "")