Skip to content

Commit

Permalink
Share image URL with Instagram
Browse files Browse the repository at this point in the history
  • Loading branch information
bjtitus committed Nov 27, 2024
1 parent 5fa9dd0 commit ac61034
Showing 1 changed file with 25 additions and 1 deletion.
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 ac61034

Please sign in to comment.