cards-native/ShareExtension/ShareViewController.swift
Till JS 4dfb32ba25 chore: Rebrand auf ev.mana.cardecky
Apple-Developer-Portal-App-ID lautet ev.mana.cardecky (analog zur
Domain cardecky.mana.how). Alle Bundle-IDs, App-Group, Keychain-
Group, OSLog-Subsysteme, URL-Schemes, Widget-Kind, App-Intent-Phrases,
Marketing-Texte und Doku nachgezogen.

Bundle-IDs neu:
- Main: ev.mana.cardecky
- Widget: ev.mana.cardecky.widget
- Share: ev.mana.cardecky.share
- Tests: ev.mana.cardecky.tests / .uitests

App-Group: group.ev.mana.cardecky
Keychain-Access-Group: $(AppIdentifierPrefix)ev.mana.cardecky
OSLog-Subsystem: ev.mana.cardecky

AASA gleichzeitig in cards-Repo angepasst (Commit 21ec535) und
auf mana-server redeployed — Probe liefert appID
"QP3GLU8PH3.ev.mana.cardecky".

Plus: ShareExtension/Resources/Info.plist + entitlements werden
jetzt analog zu Widget-Resources gitignored (sind XcodeGen-generated).

35 Unit-Tests + 1 UI-Test grün, alle drei Targets bauen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 13:29:04 +02:00

78 lines
2.8 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 {
self.sharedURL = url.absoluteString
if self.sharedText.isEmpty { self.sharedText = url.absoluteString }
}
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 { self.sharedText = text }
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))
}
}
}