Skip to content

Commit

Permalink
Playback 2024: Instagram share fix (#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjtitus authored Nov 27, 2024
2 parents 5fa9dd0 + 0260816 commit e47d3d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
7.78
-----

7.77.1
-----
- Fix sharing Playback stories to Instagram [#2482](https://github.com/Automattic/pocket-casts-ios/pull/2482)

7.77
-----
Expand Down
26 changes: 25 additions & 1 deletion podcasts/End of Year/StoryShareableProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class StoryShareableProvider: UIActivityItemProvider {

var generatedItem: Any?

var generatedItemURL: Any?

var view: AnyView?

static func new(_ view: AnyView) -> StoryShareableProvider {
Expand All @@ -26,7 +28,11 @@ class StoryShareableProvider: UIActivityItemProvider {

override var item: Any {
get {
generatedItem ?? UIImage()
if activityType?.rawValue.contains("instagram") == true {
generatedItemURL ?? NSURL()
} else {
generatedItem ?? UIImage()
}
}
}

Expand All @@ -44,9 +50,27 @@ class StoryShareableProvider: UIActivityItemProvider {
.frame(width: 370, height: 800)
.snapshot()

let snapshotURL = save(snapshot: snapshot)
generatedItemURL = snapshotURL
generatedItem = snapshot
self.view = nil
}

private func save(snapshot: UIImage) -> URL? {
guard let imageData = snapshot.pngData() else { return nil }

let tempDir = FileManager.default.temporaryDirectory
let uuid = UUID().uuidString
let url = tempDir.appendingPathComponent("pocket-casts-share-image-\(uuid).png")

do {
try imageData.write(to: url)
} catch {
return nil
}

return url
}
}

extension EnvironmentValues {
Expand Down

0 comments on commit e47d3d9

Please sign in to comment.