FBSDKShareTournamentDialog.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  3. *
  4. * You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  5. * copy, modify, and distribute this software in source code or binary form for use
  6. * in connection with the web services and APIs provided by Facebook.
  7. *
  8. * As with any software that integrates with the Facebook platform, your use of
  9. * this software is subject to the Facebook Developer Principles and Policies
  10. * [http://developers.facebook.com/policy/]. This copyright notice shall be
  11. * included in all copies or substantial portions of the software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  15. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  16. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  17. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  18. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. import FBSDKCoreKit
  21. import FBSDKGamingServicesKit
  22. import Foundation
  23. @objc
  24. public protocol FBSDKShareTournamentDialogDelegate: AnyObject {
  25. func didComplete(dialog: FBSDKShareTournamentDialog, tournament: FBSDKTournament)
  26. func didFail(withError error: Error, dialog: FBSDKShareTournamentDialog)
  27. func didCancel(dialog: FBSDKShareTournamentDialog)
  28. }
  29. /// An internal wrapper for sharing tournaments via dialog
  30. @objcMembers
  31. public final class FBSDKShareTournamentDialog: NSObject, ShareTournamentDialogDelegate {
  32. weak var delegate: FBSDKShareTournamentDialogDelegate?
  33. private var dialog: ShareTournamentDialog?
  34. public init(delegate: FBSDKShareTournamentDialogDelegate) {
  35. self.delegate = delegate
  36. super.init()
  37. dialog = ShareTournamentDialog(delegate: self)
  38. }
  39. public func show(score: Int, tournamentID: String) throws {
  40. try dialog?.show(score: score, tournamentID: tournamentID)
  41. }
  42. public func show(
  43. initialScore: Int,
  44. title: String? = nil,
  45. endTime: Date? = nil,
  46. scoreType: Int,
  47. sortOrder: Int,
  48. payload: String? = nil
  49. ) throws {
  50. let currentConfig = TournamentConfig(
  51. title: title,
  52. endTime: endTime,
  53. scoreType: scoreType == 0 ? .numeric : .time,
  54. sortOrder: sortOrder == 0 ? .higherIsBetter : .lowerIsBetter,
  55. image: nil,
  56. payload: payload
  57. )
  58. try dialog?.show(initialScore: initialScore, config: currentConfig)
  59. }
  60. // MARK: FBSDKShareTournamentDialogDelegate
  61. public func didComplete(dialog: ShareTournamentDialog, tournament: Tournament) {
  62. delegate?.didComplete(dialog: self, tournament: FBSDKTournament(tournament: tournament))
  63. }
  64. public func didFail(withError error: Error, dialog: ShareTournamentDialog) {
  65. delegate?.didFail(withError: error, dialog: self)
  66. }
  67. public func didCancel(dialog: ShareTournamentDialog) {
  68. delegate?.didCancel(dialog: self)
  69. }
  70. }