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.

96 lines
3.1 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 UIKit
  20. import FBSDKShareKit
  21. /**
  22. A photo for sharing.
  23. */
  24. public struct Photo {
  25. /// If the photo is resident in memory, this method supplies the data.
  26. public var image: UIImage?
  27. /// The URL to the photo.
  28. public var url: URL?
  29. /// Specifies whether the photo represented by the receiver was generated by the user or by the application.
  30. public var isUserGenerated: Bool
  31. /**
  32. The user generated caption for the photo. Note that the 'caption' must come from the user, as pre-filled content
  33. is forbidden by the Platform Policies (2.3).
  34. */
  35. public var caption: String?
  36. /**
  37. Conveniece method to Create a `Photo` with an image.
  38. - parameter image: The image to create with.
  39. - parameter userGenerated: Whether or not this image was user generated.
  40. */
  41. public init(image: UIImage, userGenerated: Bool) {
  42. self.image = image
  43. self.isUserGenerated = userGenerated
  44. }
  45. /**
  46. Conveniece method to Create a `Photo` with an image.
  47. - parameter url: The image URL to create with.
  48. - parameter userGenerated: Whether or not this image was user generated.
  49. */
  50. public init(url: URL, userGenerated: Bool) {
  51. self.url = url
  52. self.isUserGenerated = userGenerated
  53. }
  54. }
  55. extension Photo {
  56. internal var sdkPhotoRepresentation: FBSDKSharePhoto {
  57. let photo = FBSDKSharePhoto()
  58. photo.image = image
  59. photo.imageURL = url
  60. photo.isUserGenerated = isUserGenerated
  61. photo.caption = caption
  62. return photo
  63. }
  64. internal init(sdkPhoto: FBSDKSharePhoto) {
  65. self.image = sdkPhoto.image
  66. self.url = sdkPhoto.imageURL
  67. self.isUserGenerated = sdkPhoto.isUserGenerated
  68. self.caption = sdkPhoto.caption
  69. }
  70. }
  71. extension Photo: Equatable {
  72. /**
  73. Compare to photos for equality.
  74. - parameter lhs: The first photo to compare.
  75. - parameter rhs: The second photo to compare.
  76. - returns: Whether or not the photos are equal.
  77. */
  78. public static func == (lhs: Photo, rhs: Photo) -> Bool {
  79. return lhs.sdkPhotoRepresentation == rhs.sdkPhotoRepresentation
  80. }
  81. }