You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.2 KiB

6 years ago
  1. // Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. import Foundation
  19. import FBSDKShareKit
  20. /**
  21. A model for an app invite.
  22. */
  23. public struct AppInvite {
  24. /// An app link target that will be used as a target when the user accepts the invite.
  25. public var appLink: URL
  26. /// The delivery method for this app invite.
  27. public var deliveryMethod: DeliveryMethod
  28. /// The URL to a preview image that will be displayed with the app invite.
  29. public var previewImageURL: URL?
  30. /// The promotional code and text to be displayed while sending and recieving the invite.
  31. public var promotion: (code: PromoCode, text: String)?
  32. /**
  33. Create an `AppInvite` with a link, delivery method, preview image, and promotion.
  34. - parameter appLink: The app link target.
  35. - parameter deliveryMethod: Optonal delivery method to use. Default: `.Facebook`.
  36. - parameter previewImageURL: Optional preview image to use. Default: `nil`.
  37. - parameter promotion: Optional promotion to be displayed. Default: `nil`.
  38. */
  39. public init(appLink: URL,
  40. deliveryMethod: DeliveryMethod = .facebook,
  41. previewImageURL: URL? = nil,
  42. promotion: (code: PromoCode, text: String)? = nil) {
  43. self.appLink = appLink
  44. self.deliveryMethod = deliveryMethod
  45. self.previewImageURL = previewImageURL
  46. self.promotion = promotion
  47. }
  48. }
  49. extension AppInvite: Equatable {
  50. /**
  51. Compare two `AppInvite`s for equality.
  52. - parameter lhs: The first invite to compare.
  53. - parameter rhs: The second invite to compare.
  54. - returns: Whether or not the invites are equal.
  55. */
  56. public static func == (lhs: AppInvite, rhs: AppInvite) -> Bool {
  57. return lhs.sdkInviteRepresentation == rhs.sdkInviteRepresentation
  58. }
  59. }
  60. extension AppInvite {
  61. internal var sdkInviteRepresentation: FBSDKAppInviteContent {
  62. let sdkContent = FBSDKAppInviteContent()
  63. sdkContent.appLinkURL = appLink
  64. sdkContent.appInvitePreviewImageURL = previewImageURL
  65. sdkContent.promotionCode = promotion?.code.rawValue
  66. sdkContent.promotionText = promotion?.text
  67. sdkContent.destination = deliveryMethod.sdkDestinationRepresentation
  68. return sdkContent
  69. }
  70. }