Skip to main content
coreydaley.dev

Taking Secret Store from the Mac to iPhone and iPad

Update, November 20, 2026: the iPhone and iPad version is on the App Store, as part of Secret Store 1.2. This post covers the port itself.

Secret Store is now a universal iPhone and iPad app. The port went faster than I expected, and the reason is boring: from the first day, the logic lived in a Swift package. The keychain store, the view-model, the free-tier gate, the clipboard policy and the lock rules are all in SecretStoreCore. Adding .iOS(.v17) to the package’s platforms was a one-line change, and the core compiled for the iOS simulator with no code changes. The app is one multiplatform Xcode target on top of it.

So the work wasn’t rewriting the app. It was finding every place the Mac version assumed it was on a Mac.

The app switcher takes a screenshot

On the Mac, Secret Store doesn’t lock when you switch apps. Like Apple’s Passwords app, it relies on an inactivity timeout and the system lock, and re-masks any revealed value when the window loses focus.

iOS adds a problem the Mac doesn’t have: when the app resigns active, the system takes a snapshot for the app switcher. If a secret is on screen, it’s in that snapshot.

The fix is a cover, added before the snapshot happens. Two details matter:

  • The handler is a NotificationCenter observer for willResignActive, not a SwiftUI scenePhase change, so it runs synchronously, in the same call stack that leads to the snapshot.
  • The cover is a plain UIView added straight to the UIWindow, not SwiftUI state. A SwiftUI change waits for the next render pass. Adding a subview is immediate.

The cover also sets accessibilityViewIsModal, so VoiceOver can’t read the content behind it. Revealed values are cleared on willResignActive as well, so the screen is masked before the cover goes on.

The iOS app doesn’t lock when you leave it either. It locks when you come back, if you were away longer than the auto-lock interval. That decision is a pure function in the core package:

public func shouldLockOnForeground(
    backgroundedAt: ContinuousClock.Instant,
    now: ContinuousClock.Instant,
    interval: Duration
) -> Bool {
    guard now >= backgroundedAt else { return true }  // fail closed
    return (now - backgroundedAt) >= interval
}

ContinuousClock is monotonic, so changing the clock can’t shorten the time you were away, and if time ever appears to run backwards the answer is to lock. Six unit tests cover the thresholds, the backward case, and a zero interval.

The pasteboard: local, and it expires

On the Mac, copying a secret writes it to NSPasteboard with the concealed and transient markers that clipboard managers respect, clears it after 90 seconds if it’s still ours, and clears it when the app quits.

UIPasteboard has no such markers, and an iOS app can be suspended or killed before its timer fires. The iOS adapter uses the two options UIPasteboard does have:

static func writeOptions(forDelay delay: Duration) -> [UIPasteboard.OptionsKey: Any] {
    [
        .localOnly: true,
        .expirationDate: Date(timeIntervalSinceNow: Double(delay.components.seconds))
    ]
}

localOnly keeps the secret out of Universal Clipboard, so it doesn’t appear on your Mac. expirationDate lets the system clear it even if the app is no longer running. The in-app timer still clears it in the foreground. The expiry date is the backstop.

The options builder is a static function so a test can check both values without a live pasteboard. That turned out to matter. An iOS UI test that read UIPasteboard.general from the test runner set off the system’s paste permission alert and hung the run. The UI tests now check the app’s own “Copied” indicator instead. That’s the more honest test anyway: a cross-app pasteboard read is exactly what the app is designed to avoid.

Backups leave the app a different way. On the Mac, Back Up picks a destination with NSSavePanel. iOS has no save panel, so the iOS path writes the backup to a unique subdirectory of the temporary directory and presents a UIActivityViewController, wrapped in a small UIViewControllerRepresentable. When the share sheet finishes, its completion handler deletes that directory, so the backup file doesn’t sit around after you’ve saved or sent it. Restore needed nothing: .fileImporter is cross-platform SwiftUI.

Scenes: the paywall becomes a sheet

On macOS the app has two scenes: the main Window and a separate Window for the paywall. The paywall has its own window there because StoreKit’s purchase sheet needs to attach to the main window, and macOS allows one sheet per window.

iOS doesn’t have that limit. The iOS scene is a WindowGroup, and the paywall is an ordinary sheet:

WindowGroup {
    ContentView(vm: viewModel)
        .task { viewModel.startEntitlementObserver() }
        .sheet(isPresented: $viewModel.showingPaywall) {
            PaywallView(provider: viewModel.entitlementProvider)
        }
}

The showingPaywall flag and the code that decides when to set it live in the core package and didn’t change. Only how each platform presents it differs. The layout needed nothing: NavigationSplitView already collapses to a stack on iPhone and shows columns on iPad.

Built for fingers

On the Mac, copy and edit live in the menu bar and the detail pane’s toolbar. On iPhone, the place you reach for is the row itself. Each row has a context menu with Copy Name, Copy Value and Edit. Copy Value copies without ever showing the value on screen. Copy Name uses localOnly too, because the names of your secrets are private as well. Edit is disabled while the app is locked, or when the over-cap edit lock applies.

Rows also have a trailing swipe to delete, with allowsFullSwipe: false. The swipe shows the Delete button. It doesn’t delete. Tapping it opens the same confirmation the Mac uses. A secret is the wrong thing to lose to a careless swipe.

The first iOS build reused the Mac sheets as they were: a title, the form, and Cancel and Add side by side in the bottom-right corner. That’s normal on macOS. On a phone, two small text buttons next to each other are an easy mis-tap, and they aren’t where iOS users look.

Every modal now branches its chrome by platform. On iOS the form sits in a NavigationStack with a title, and the buttons go in the navigation bar, Cancel on the leading side and the confirm action on the trailing side:

.toolbar {
    ToolbarItem(placement: .cancellationAction) {
        Button("Cancel") { cancel() }
    }
    ToolbarItem(placement: .confirmationAction) {
        Button("Add") { save() }.disabled(!canSave)
    }
}

The form itself is shared between the two layouts. The accessibility identifiers moved onto the toolbar buttons, so the UI tests didn’t need changes. iPad with a hardware keyboard also gets the Mac’s shortcuts where they make sense, starting with ⌘L to lock and ⇧⌘N for a new secret.

What stays on the Mac

Two features stay macOS-only, behind #if os(macOS):

  • Crash reporting. Secret Store uses the same no-network approach I described for Purrchiver: read the crash reports macOS writes, scrub them, and offer an email the user can choose to send. The kit is built on AppKit and macOS file locations, so on iOS it isn’t compiled at all.
  • Word .docx import. The Mac extracts text from .docx with NSAttributedString’s Office Open XML reader, which is AppKit-only. On iOS, a file with a .docx signature now returns a clear unsupportedFormat error. RTF and PDF import work on both.

The iOS entitlements file is short: the keychain access group and nothing else. As on the Mac, there are no network entitlements.

A test that pins the keychain

Not every part of a port should change. Storage is the one place it must not. Every synced item is bound to a keychain access group, and changing that group after release orphans every secret on every device. The other attributes are just as easy to break with a “fix”: switching to a ThisDeviceOnly accessibility class looks like a harmless tightening and quietly stops the item from syncing.

So the port added a regression gate. The keychain store builds its query dictionaries in two internal functions, and a test suite asserts on them directly, with no live SecItemAdd:

  • the access group and both service names are byte-for-byte the pinned values, and the access group flows into the actual write query;
  • writes set kSecUseDataProtectionKeychain and kSecAttrSynchronizable to true, and use kSecAttrAccessibleWhenUnlocked;
  • reads use kSecAttrSynchronizableAny and the data-protection keychain.

The suite passes on macOS and the iOS simulator.

Tests on both platforms

A new iOS UI-test target ports the main flows from the Mac XCUITests to touch: add, copy, lock and unlock, import, restore from a backup, and the paywall’s buy and restore paths (against a fake entitlement provider). All nine pass on the iPhone 17 and iPad (A16) simulators. They run on a runner inside a logged-in GUI session, for the reasons in this post about StoreKit tests.

What’s left needs a person holding a device: purchase and restore on real hardware, and a look at the iPad shortcut overlay.

What to take away

  • Put the logic in a package from the start. Then a port is mostly views.
  • Look for the new platform’s own privacy holes, like the app-switcher snapshot, rather than only porting the old platform’s defenses.
  • Use the system’s pasteboard options: localOnly and expirationDate keep working after your app stops.
  • Pin your storage attributes with a test before a port gives anyone a reason to “fix” them.

What did your app assume about its first platform that only showed up when you ported it?

Related posts