Guest User

Untitled

a guest
Jan 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. @IBAction func startTapped(_ sender: Any) {
  2. let request = GKMatchRequest()
  3. request.maxPlayers = 2
  4. request.minPlayers = 1
  5.  
  6. let mmvc = GKMatchmakerViewController(matchRequest: request)
  7. mmvc?.matchmakerDelegate = self
  8. present(mmvc!, animated: true, completion: nil)
  9. }
  10.  
  11. extension HomeVC: GKGameCenterControllerDelegate
  12. {
  13.  
  14. func authenticatePlayer()
  15. {
  16. //CALLED ON VIEWDIDAPPEAR
  17. let localPlayer = GKLocalPlayer.localPlayer()
  18.  
  19. localPlayer.authenticateHandler = {
  20. (view, error) in
  21. if view != nil
  22. {
  23. self.present(view!, animated: true, completion: nil)
  24. } else {
  25. print("AUTHENTICATED!")
  26. print(GKLocalPlayer.localPlayer().isAuthenticated)
  27. }
  28. }
  29. }
  30. func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
  31. gameCenterViewController.dismiss(animated: true, completion: nil)
  32. }
  33. }
  34.  
  35. extension HomeVC: GKMatchmakerViewControllerDelegate {
  36. func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
  37. print("match was cancelled")
  38. viewController.dismiss(animated: true, completion: nil)
  39. }
  40.  
  41. func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
  42. print("didFailwithError: (error.localizedDescription)")
  43. }
  44.  
  45. func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
  46.  
  47. print("Match found, ID: (match.description)")
  48. let gameScreenVC = self.storyboard?.instantiateViewController(withIdentifier: "mainGame") as! ViewController
  49. gameScreenVC.providesPresentationContextTransitionStyle = true
  50. gameScreenVC.definesPresentationContext = true
  51. gameScreenVC.modalPresentationStyle = UIModalPresentationStyle.fullScreen
  52. gameScreenVC.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
  53. match.delegate = gameScreenVC
  54.  
  55. self.present(gameScreenVC, animated: true, completion: nil)
  56.  
  57. }
  58. }
Add Comment
Please, Sign In to add comment