mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Add share extension, rework bookmarks model
This commit is contained in:
26
Open in Yattee/Info.plist
Normal file
26
Open in Yattee/Info.plist
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionAttributes</key>
|
||||
<dict>
|
||||
<key>NSExtensionActivationRule</key>
|
||||
<string>SUBQUERY (
|
||||
extensionItems,
|
||||
$extensionItem,
|
||||
SUBQUERY (
|
||||
$extensionItem.attachments,
|
||||
$attachment,
|
||||
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.url"
|
||||
).@count == $extensionItem.attachments.@count
|
||||
).@count > 0</string>
|
||||
</dict>
|
||||
<key>NSExtensionPointIdentifier</key>
|
||||
<string>com.apple.share-services</string>
|
||||
<key>NSExtensionPrincipalClass</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
10
Open in Yattee/Open in Yattee.entitlements
Normal file
10
Open in Yattee/Open in Yattee.entitlements
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array>
|
||||
<string>group.stream.yattee.app.bookmarks</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
54
Open in Yattee/ShareViewController.swift
Normal file
54
Open in Yattee/ShareViewController.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
import Social
|
||||
import UIKit
|
||||
|
||||
final class ShareViewController: SLComposeServiceViewController {
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
for item in extensionContext!.inputItems as! [NSExtensionItem] {
|
||||
if let attachments = item.attachments {
|
||||
for itemProvider in attachments where itemProvider.hasItemConformingToTypeIdentifier("public.url") {
|
||||
itemProvider.loadItem(forTypeIdentifier: "public.url", options: nil) { item, _ in
|
||||
if let url = (item as? NSURL), let absoluteURL = url.absoluteURL {
|
||||
URLBookmarkModel.shared.saveBookmark(absoluteURL)
|
||||
if let url = URL(string: "yattee://\(absoluteURL.absoluteString)") {
|
||||
self.open(url: url)
|
||||
}
|
||||
}
|
||||
self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func open(url: URL) {
|
||||
var responder: UIResponder? = self as UIResponder
|
||||
let selector = #selector(openURL(_:))
|
||||
|
||||
while responder != nil {
|
||||
if responder!.responds(to: selector), responder != self {
|
||||
responder!.perform(selector, with: url)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
responder = responder?.next
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func openURL(_: URL) {}
|
||||
|
||||
override func isContentValid() -> Bool {
|
||||
true
|
||||
}
|
||||
|
||||
override func didSelectPost() {
|
||||
extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
|
||||
override func configurationItems() -> [Any]! {
|
||||
[]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user