我希望一切顺利
请使用乘数连接框架创建可在附近设备之间共享照片的应用。
我每次按下连接时都会出现问题,当我分享会话时,浏览器会告诉我已连接但我收到此消息并且发送的照片在错误消息下方失败:
[ERROR] ProcessEvent:1199 Send BINDING_REQUEST failed(C01A0000).
[GCKSession] Not in connected state, so giving up for participant [7A5C490D] on channel [0].
[GCKSession] Not in connected state, so giving up for participant [7A5C490D] on channel [1].
[ERROR] ICEStopConnectivityCheck:2688 ICEStopConnectivityCheck() found no ICE check with call id (2052868365)
[GCKSession] Not in connected state, so giving up for participant [7A5C490D] on channel [2].
[ERROR] ICEStopConnectivityCheck:2688 ICEStopConnectivityCheck() found no ICE check with call id (2052868365)
我在下面使用它的代码:
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
peerID = MCPeerID(displayName: UIDevice.current.name)
// init the session
mcSession = MCSession(peer: peerID, securityIdentity: nil, encryptionPreference: .none)
mcSession.delegate = self
}
@IBAction func showAlertForShare(_ sender: UIBarButtonItem) {
let alertController = UIAlertController(title: "Share Photos", message: "Do You Want Share The Photo With Other User?", preferredStyle: .actionSheet)
let alertHostSession = UIAlertAction(title: "Host A Session", style: .default) { (alertAction) in
self.mcAdvertiserAssistant = MCAdvertiserAssistant(serviceType: "hws-desertqwert", discoveryInfo: nil, session: self.mcSession)
self.mcAdvertiserAssistant.start()
}
let alertJoinSession = UIAlertAction(title: "Join A Session", style: .default) { (alertAction) in
self.mcbrowserViewController = MCBrowserViewController(serviceType: "hws-desertqwert", session: self.mcSession)
self.mcbrowserViewController.delegate = self
self.present(self.mcbrowserViewController, animated: true, completion: nil)
}
let alertCancel = UIAlertAction(title: "Cancel", style: .cancel) { (alertAction) in
alertController.dismiss(animated: true, completion: nil)
}
alertController.addAction(alertHostSession)
alertController.addAction(alertJoinSession)
alertController.addAction(alertCancel)
self.present(alertController, animated: true, completion: nil)
}
// multipeer delegate methods
func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
switch state {
case .connected:
print("Connected: \(peerID)")
case .connecting:
print("Connecting: \(peerID)")
case .notConnected:
print("Not Connecting: \(peerID)")
}
}
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
print(data)
if let getImage = UIImage(data: data) {
print(self.mcSession.connectedPeers.count)
self.arrayOfImages.append(getImage)
DispatchQueue.main.async {
self.collectionView.reloadData()
}
}
}
func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
}
func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
}
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL?, withError error: Error?) {
}
func browserViewControllerDidFinish(_ browserViewController: MCBrowserViewController) {
self.dismiss(animated: true, completion: nil)
}
func browserViewControllerWasCancelled(_ browserViewController: MCBrowserViewController) {
self.dismiss(animated: true, completion: nil)
}
所以任何人都可以解决这个问题吗?
非常感谢