-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ee8823
commit cb5c239
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Rob Jonson on 10/04/2021. | ||
// | ||
|
||
#if canImport(UIKit) && !os(watchOS) | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
public extension UIViewController { | ||
|
||
@objc | ||
func share(items:[ShareItem],sourceView:UIView? = nil,permittedArrowDirections:UIPopoverArrowDirection = []) { | ||
|
||
guard let view = sourceView ?? self.view else { | ||
return | ||
} | ||
|
||
let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil) | ||
|
||
if let popoverPC = activityViewController.popoverPresentationController { | ||
popoverPC.sourceView = view | ||
popoverPC.sourceRect = view.bounds | ||
popoverPC.permittedArrowDirections = permittedArrowDirections | ||
} | ||
|
||
self.present(activityViewController, animated: true) | ||
|
||
} | ||
} | ||
|
||
@objc | ||
public class ShareItem: NSObject, UIActivityItemSource { | ||
|
||
private let subject:String | ||
private let item:Any | ||
|
||
public init(subject: String, item: Any) { | ||
self.subject = subject | ||
self.item = item | ||
|
||
super.init() | ||
} | ||
|
||
public func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { | ||
return item | ||
} | ||
|
||
public func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { | ||
return item | ||
} | ||
|
||
public func activityViewController(_ activityViewController: UIActivityViewController, | ||
subjectForActivityType activityType: UIActivity.ActivityType?) -> String { | ||
return subject | ||
} | ||
} | ||
|
||
#endif |