diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d32c966f..f56a81f34f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- diff --git a/podcasts/End of Year/StoryShareableProvider.swift b/podcasts/End of Year/StoryShareableProvider.swift index af73a21a27..b2416929e3 100644 --- a/podcasts/End of Year/StoryShareableProvider.swift +++ b/podcasts/End of Year/StoryShareableProvider.swift @@ -12,6 +12,8 @@ class StoryShareableProvider: UIActivityItemProvider { var generatedItem: Any? + var generatedItemURL: Any? + var view: AnyView? static func new(_ view: AnyView) -> StoryShareableProvider { @@ -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() + } } } @@ -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 {