#if DEBUG && os(iOS) && targetEnvironment(simulator) import SwiftUI import UIKit /// Real system share sheet, real extension and its keychain grants, with a /// disposable recipient and transport. Cannot run on a physical iPhone. public struct ShareFixture: View { @State private var sharing = false @State private var file: URL? let mode = ProcessInfo.processInfo.environment["EQUIPO_SHARE_FIXTURE"] ?? "compose" public init() {} public var body: some View { NavigationStack { VStack(spacing: 20) { Image(systemName: "square.and.arrow.up").font(.largeTitle) Button(EquipoStrings.text("native.share.title")) { sharing = true } .buttonStyle(.borderedProminent).disabled(file == nil) }.navigationTitle(EquipoStrings.text("app.name")) }.task { configure() } .sheet(isPresented: $sharing) { if let file { ShareHost(items: [file, "The sign-in button is cut off on my phone."]) } } } private func configure() { let accounts = DeviceAccounts(store: KeychainSecretStore.shared) let origin = URL(string: "https://share-fixture.invalid")! var account = accounts.all().first { $0.origin == origin } ?? DeviceAccount.new(origin: origin, label: "Fixture") account.address = "paul@example.com"; account.teamName = "Oficina" account.credential = DeviceCredential(id: "fixture", token: "fixture-share", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: Date().addingTimeInterval(3600)) do { try accounts.commit(.save(account), lifetime: accounts.lifetimes.current) try accounts.commit(.selectForSharing(account), lifetime: accounts.lifetimes.current) if mode == "signed-out" { try accounts.commit(.remove(account), lifetime: accounts.lifetimes.current) } let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] let large = docs.appendingPathComponent("large.heic") if mode == "large", FileManager.default.fileExists(atPath: large.path) { file = large } else { let path = docs.appendingPathComponent("Home.png") // Fixture bytes only. Persistent secrets still use commit above. try ShareFixtureFiles.save(AttachmentsFixture.image, to: path) file = path } } catch { if case KeychainSecretStore.StoreError.keychain(let status) = error { NSLog("Share fixture keychain status=%d", status) } file = nil } } } private struct ShareHost: UIViewControllerRepresentable { let items: [Any] func makeUIViewController(context: Context) -> UIActivityViewController { UIActivityViewController(activityItems: items, applicationActivities: nil) } func updateUIViewController(_ view: UIActivityViewController, context: Context) {} } #endif