Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] #209 - 사파리 외에 다른 앱에서도 Share Extension 대응 #210

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ToasterShareExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsURLWithMaxCount</key>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
</dict>
</dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
17 changes: 10 additions & 7 deletions ToasterShareExtension/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ private extension ShareViewController {
// 웹 사이트 URL 를 받아올 수 있는 메서드
func getUrl() {
if let item = extensionContext?.inputItems.first as? NSExtensionItem,
let itemProvider = item.attachments?.first as? NSItemProvider,
itemProvider.hasItemConformingToTypeIdentifier("public.url") {
itemProvider.loadItem(forTypeIdentifier: "public.url", options: nil) { [weak self] (url, error) in
if let shareURL = url as? URL {
self?.urlString = shareURL.absoluteString
} else {
print("Error loading URL: \(error?.localizedDescription ?? "")")
let itemProviders = item.attachments {
itemProviders.forEach { itemProvider in
if itemProvider.hasItemConformingToTypeIdentifier("public.url") {
itemProvider.loadItem(forTypeIdentifier: "public.url") { [weak self] (url, error) in
if let shareURL = url as? URL {
self?.urlString = shareURL.absoluteString
} else {
print("Error loading URL: \(error?.localizedDescription ?? "")")
}
}
}
}
}
Expand Down