From 7a6c369699039d250ede7069d01fab4352d54c5f Mon Sep 17 00:00:00 2001 From: chanhihi Date: Tue, 23 Apr 2024 08:48:36 +0900 Subject: [PATCH 1/6] feat: register subquery extensionItems public.data --- Project.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Project.swift b/Project.swift index 4fa1bf0..9d57166 100644 --- a/Project.swift +++ b/Project.swift @@ -64,8 +64,19 @@ class iBoxFactory: ProjectFactory { "NSExtension": [ "NSExtensionAttributes": [ "NSExtensionActivationRule": [ - "NSExtensionActivationSupportsWebPageWithMaxCount" : 1, - "NSExtensionActivationSupportsWebURLWithMaxCount" : 1 + "NSExtensionActivationSupportsWebPageWithMaxCount": 1, + "NSExtensionActivationSupportsWebURLWithMaxCount": 1, + "SUBQUERY": [ + "extensionItems": [ + "SUBQUERY": [ + "attachments": [ + "ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO 'public.data'": "TRUE" + ], + "@count": 1 + ] + ], + "@count": 1 + ] ] ], "NSExtensionPointIdentifier": "com.apple.share-services", From 353f1db0127f92abc5f07199b48480103a6534c5 Mon Sep 17 00:00:00 2001 From: chanhihi Date: Tue, 23 Apr 2024 09:11:00 +0900 Subject: [PATCH 2/6] fix: support file, movie, image --- Project.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Project.swift b/Project.swift index 9d57166..73c8e2e 100644 --- a/Project.swift +++ b/Project.swift @@ -66,6 +66,9 @@ class iBoxFactory: ProjectFactory { "NSExtensionActivationRule": [ "NSExtensionActivationSupportsWebPageWithMaxCount": 1, "NSExtensionActivationSupportsWebURLWithMaxCount": 1, + "NSExtensionActivationSupportsImageWithMaxCount": 1, + "NSExtensionActivationSupportsMovieWithMaxCount": 1, + "NSExtensionActivationSupportsFileWithMaxCount": 1, "SUBQUERY": [ "extensionItems": [ "SUBQUERY": [ From dab32ad1efa5110a0c2b5a822de7c588240f56d9 Mon Sep 17 00:00:00 2001 From: chanhihi Date: Tue, 23 Apr 2024 09:12:13 +0900 Subject: [PATCH 3/6] feat: add extension item --- .../Sources/ShareViewController.swift | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/ShareExtension/Sources/ShareViewController.swift b/ShareExtension/Sources/ShareViewController.swift index f7493a6..15b3437 100644 --- a/ShareExtension/Sources/ShareViewController.swift +++ b/ShareExtension/Sources/ShareViewController.swift @@ -71,7 +71,30 @@ class CustomShareViewController: UIViewController { } func extractSharedURL() { - guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem else { return } + guard let extensionItem = extensionContext?.inputItems.first as? NSExtensionItem else { + print("No extension items found.") + return + } + + if let item = extensionContext?.inputItems.first as? NSExtensionItem { + for attachment in item.attachments ?? [] { + if let itemProvider = attachment as? NSItemProvider { + if itemProvider.hasItemConformingToTypeIdentifier("public.plain-text") { + // 텍스트 데이터 로드 + itemProvider.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { (data, error) in + DispatchQueue.main.async { + if let text = data as? String { + // 텍스트에서 URL 추출 + self.extractURL(fromText: text) + } else { + print("Error loading text: \(String(describing: error))") + } + } + } + } + } + } + } for attachment in extensionItem.attachments ?? [] { if attachment.hasItemConformingToTypeIdentifier(UTType.url.identifier) { @@ -86,10 +109,24 @@ class CustomShareViewController: UIViewController { } } break + } else { + print("Attachment does not conform to URL type.") } } } + private func extractURL(fromText text: String) { + let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) + let matches = detector?.matches(in: text, options: [], range: NSRange(location: 0, length: text.utf8.count)) + + if let firstMatch = matches?.first, let range = Range(firstMatch.range, in: text), let url = URL(string: String(text[range])) { + print("Extracted URL: \(url)") + self.dataURL = url.absoluteString + } else { + print("No URL found in text") + } + } + // MARK: IBAction @IBAction func cancel() { From 863b7fc98b6c1805532499b81abfeada86e275cc Mon Sep 17 00:00:00 2001 From: chanhihi Date: Tue, 23 Apr 2024 09:16:59 +0900 Subject: [PATCH 4/6] chore: delete commnets --- ShareExtension/Sources/ShareViewController.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/ShareExtension/Sources/ShareViewController.swift b/ShareExtension/Sources/ShareViewController.swift index 15b3437..de61ad6 100644 --- a/ShareExtension/Sources/ShareViewController.swift +++ b/ShareExtension/Sources/ShareViewController.swift @@ -80,11 +80,9 @@ class CustomShareViewController: UIViewController { for attachment in item.attachments ?? [] { if let itemProvider = attachment as? NSItemProvider { if itemProvider.hasItemConformingToTypeIdentifier("public.plain-text") { - // 텍스트 데이터 로드 itemProvider.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { (data, error) in DispatchQueue.main.async { if let text = data as? String { - // 텍스트에서 URL 추출 self.extractURL(fromText: text) } else { print("Error loading text: \(String(describing: error))") From d09c2c14fbf0602f0fe4e99306cfa5cf934a2848 Mon Sep 17 00:00:00 2001 From: chanhihi Date: Tue, 23 Apr 2024 09:32:09 +0900 Subject: [PATCH 5/6] fix: delete unnecessary line --- ShareExtension/Sources/ShareViewController.swift | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ShareExtension/Sources/ShareViewController.swift b/ShareExtension/Sources/ShareViewController.swift index de61ad6..d81bf15 100644 --- a/ShareExtension/Sources/ShareViewController.swift +++ b/ShareExtension/Sources/ShareViewController.swift @@ -78,15 +78,13 @@ class CustomShareViewController: UIViewController { if let item = extensionContext?.inputItems.first as? NSExtensionItem { for attachment in item.attachments ?? [] { - if let itemProvider = attachment as? NSItemProvider { - if itemProvider.hasItemConformingToTypeIdentifier("public.plain-text") { - itemProvider.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { (data, error) in - DispatchQueue.main.async { - if let text = data as? String { - self.extractURL(fromText: text) - } else { - print("Error loading text: \(String(describing: error))") - } + if attachment.hasItemConformingToTypeIdentifier("public.plain-text") { + attachment.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { (data, error) in + DispatchQueue.main.async { + if let text = data as? String { + self.extractURL(fromText: text) + } else { + print("Error loading text: \(String(describing: error))") } } } From 0cc1efb7e8f5106e4fe3c858e5642141027827c0 Mon Sep 17 00:00:00 2001 From: KIM CHANHEE <85754295+chanhihi@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:34:16 +0900 Subject: [PATCH 6/6] fix: delete unnecessary line --- Project.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Project.swift b/Project.swift index 73c8e2e..9d57166 100644 --- a/Project.swift +++ b/Project.swift @@ -66,9 +66,6 @@ class iBoxFactory: ProjectFactory { "NSExtensionActivationRule": [ "NSExtensionActivationSupportsWebPageWithMaxCount": 1, "NSExtensionActivationSupportsWebURLWithMaxCount": 1, - "NSExtensionActivationSupportsImageWithMaxCount": 1, - "NSExtensionActivationSupportsMovieWithMaxCount": 1, - "NSExtensionActivationSupportsFileWithMaxCount": 1, "SUBQUERY": [ "extensionItems": [ "SUBQUERY": [