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.

145 lines
4.9 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 status and link content to be shared
  22. */
  23. public struct LinkShareContent: ContentProtocol {
  24. public typealias Result = PostSharingResult
  25. /**
  26. The title to display for this link.
  27. This value may be discarded for specially handled links (ex: iTunes URLs).
  28. */
  29. @available(*, deprecated, message: "`title` is deprecated from Graph API 2.9")
  30. public var title: String?
  31. /**
  32. The description of the link.
  33. If not specified, this field is automatically populated by information scraped from the contentURL,
  34. typically the title of the page. This value may be discarded for specially handled links (ex: iTunes URLs).
  35. */
  36. @available(*, deprecated, message: "`description` is deprecated from Graph API 2.9")
  37. public var description: String?
  38. /**
  39. Some quote text of the link.
  40. If specified, the quote text will render with custom styling on top of the link.
  41. */
  42. public var quote: String?
  43. /// The URL of a picture to attach to this content.
  44. @available(*, deprecated, message: "`imageURL` is deprecated from Graph API 2.9")
  45. public var imageURL: URL?
  46. /**
  47. Create link share content.
  48. - parameter url: The URL being shared.
  49. - parameter title: Optional title to display for this link.
  50. - parameter description: Optional description of the link.
  51. - parameter quote: Optional quote text of the link.
  52. - parameter imageURL: OPtional image URL of a picture to attach.
  53. */
  54. @available(*, deprecated, message: "`title`, `description`, `imageURL` are deprecated from Graph API 2.9")
  55. public init(url: URL,
  56. title: String? = nil,
  57. description: String? = nil,
  58. quote: String? = nil,
  59. imageURL: URL? = nil) {
  60. self.url = url
  61. self.title = title
  62. self.description = description
  63. self.quote = quote
  64. self.imageURL = imageURL
  65. }
  66. /**
  67. Create link share content.
  68. - parameter url: The URL being shared.
  69. - parameter quote: Optional quote text of the link.
  70. */
  71. public init(url: URL,
  72. quote: String? = nil) {
  73. self.url = url
  74. self.quote = quote
  75. }
  76. //--------------------------------------
  77. // MARK - Content
  78. //--------------------------------------
  79. /**
  80. URL for the content being shared.
  81. This URL will be checked for all link meta tags for linking in platform specific ways.
  82. See documentation for App Links (https://developers.facebook.com/docs/applinks/).
  83. */
  84. public var url: URL?
  85. /// Hashtag for the content being shared.
  86. public var hashtag: Hashtag?
  87. /**
  88. List of IDs for taggable people to tag with this content.
  89. See documentation for Taggable Friends (https://developers.facebook.com/docs/graph-api/reference/user/taggable_friends)
  90. */
  91. public var taggedPeopleIds: [String]?
  92. /// The ID for a place to tag with this content.
  93. public var placeId: String?
  94. /// A value to be added to the referrer URL when a person follows a link from this shared content on feed.
  95. public var referer: String?
  96. }
  97. extension LinkShareContent: Equatable {
  98. /**
  99. Compares two `LinkContent`s for equality.
  100. - parameter lhs: One content to compare.
  101. - parameter rhs: The other content to compare to.
  102. - returns: Whether or not the content are equivalent.
  103. */
  104. public static func == (lhs: LinkShareContent, rhs: LinkShareContent) -> Bool {
  105. return lhs.sdkSharingContentRepresentation.isEqual(rhs.sdkSharingContentRepresentation)
  106. }
  107. }
  108. extension LinkShareContent: SDKBridgedContent {
  109. internal var sdkSharingContentRepresentation: FBSDKSharingContent {
  110. let content = FBSDKShareLinkContent()
  111. content.quote = self.quote
  112. content.contentURL = self.url
  113. content.hashtag = self.hashtag?.sdkHashtagRepresentation
  114. content.peopleIDs = self.taggedPeopleIds
  115. content.placeID = self.placeId
  116. content.ref = self.referer
  117. return content
  118. }
  119. }