- CFBundleShortVersionString 0.1.0 + CFBundleVersion 1 in beiden Extensions (Widget + Share), damit sie mit dem Main-Bundle matchen (Apple-Validation-Warning bei Embedded-Binary) - UISupportedInterfaceOrientations (iPhone Portrait/Landscape + iPad alle vier), behebt Validation-Warning - AppIcon mac-Slot auf size 1024x1024 (Asset-Catalog akzeptiert) - xcodeVersion: 16.0 im XcodeGen-Manifest gegen "Update to recommended settings"-Hint - ShareViewController: DispatchQueue.main.async für State-Updates aus NSItemProvider-Callbacks (Swift-6-Concurrency-Sauberkeit) - PendingShareStore.append: guard url != nil statt unused-let Archive verifiziert via xcodebuild archive -allowProvisioningUpdates: ARCHIVE SUCCEEDED, alle drei Provisioning Profiles (cardecky, cardecky.widget, cardecky.share) automatisch geholt + signiert. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
89 lines
3.1 KiB
Swift
89 lines
3.1 KiB
Swift
import SwiftUI
|
|
import UIKit
|
|
import UniformTypeIdentifiers
|
|
|
|
/// Share-Extension-Entrypoint. Liest geteilten Text/URL aus
|
|
/// `extensionContext`, persistiert als `PendingShare` in der App-Group,
|
|
/// schließt sich nach Bestätigung.
|
|
final class ShareViewController: UIViewController {
|
|
private var sharedText: String = ""
|
|
private var sharedURL: String?
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
view.backgroundColor = .systemBackground
|
|
loadSharedContent { [weak self] in
|
|
self?.presentEditor()
|
|
}
|
|
}
|
|
|
|
private func loadSharedContent(completion: @escaping () -> Void) {
|
|
guard let item = extensionContext?.inputItems.first as? NSExtensionItem,
|
|
let providers = item.attachments
|
|
else {
|
|
completion()
|
|
return
|
|
}
|
|
|
|
let group = DispatchGroup()
|
|
for provider in providers {
|
|
if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
|
|
group.enter()
|
|
provider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { item, _ in
|
|
if let url = item as? URL {
|
|
let absolute = url.absoluteString
|
|
DispatchQueue.main.async {
|
|
self.sharedURL = absolute
|
|
if self.sharedText.isEmpty { self.sharedText = absolute }
|
|
group.leave()
|
|
}
|
|
} else {
|
|
group.leave()
|
|
}
|
|
}
|
|
} else if provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
|
|
group.enter()
|
|
provider.loadItem(forTypeIdentifier: UTType.plainText.identifier, options: nil) { item, _ in
|
|
if let text = item as? String {
|
|
DispatchQueue.main.async {
|
|
self.sharedText = text
|
|
group.leave()
|
|
}
|
|
} else {
|
|
group.leave()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
group.notify(queue: .main, execute: completion)
|
|
}
|
|
|
|
private func presentEditor() {
|
|
let host = UIHostingController(rootView: ShareEditorView(
|
|
text: sharedText,
|
|
sourceURL: sharedURL,
|
|
onSave: { [weak self] cleanedText in
|
|
self?.saveAndClose(text: cleanedText)
|
|
},
|
|
onCancel: { [weak self] in
|
|
self?.cancel()
|
|
}
|
|
))
|
|
host.modalPresentationStyle = .formSheet
|
|
present(host, animated: true)
|
|
}
|
|
|
|
private func saveAndClose(text: String) {
|
|
let share = PendingShare(text: text, sourceURL: sharedURL)
|
|
PendingShareStore.append(share)
|
|
dismiss(animated: true) { [weak self] in
|
|
self?.extensionContext?.completeRequest(returningItems: nil)
|
|
}
|
|
}
|
|
|
|
private func cancel() {
|
|
dismiss(animated: true) { [weak self] in
|
|
self?.extensionContext?.cancelRequest(withError: NSError(domain: "ev.mana.cardecky.share", code: 0))
|
|
}
|
|
}
|
|
}
|