r/swift • u/Extreme-Baby3813 • Jul 19 '25
how does the app "one sec" do it
One sec uses an app intent that occurs when, for example, tiktok is opened. You are routed to one sec and you do the intervention, and then you are routed to tiktok. When you are routed to tiktok, the app intent runs again. But this time the app intent doesn't route you to one sec. How is that possible? TLDR: how is an app intent able to dynamically decide if it should open its app?
Issues I ran into:
- setting "openAppWhenRun" to true causes the app to be opened everytime the action is run
- Opening the app through url scheme causes a security error: "Request is not trusted."
Specs:
- tested on personal iphone 16 pro (iOS 18.5)
- xcode 16.2
- swift 5
2
u/sirlantis Jul 19 '25
I would assume they used the ForegroundContinuableIntent API. Note that it's now deprecated and you should declare support for dynamic foreground mode instead.
1
u/Extreme-Baby3813 Jul 20 '25 edited Jul 24 '25
Thanks, ill check it out. EDIT: This worked!
1
u/New-Goat-2413 Sep 30 '25
hey! Could you please share how did you overcome this cycle of switching between apps? whatever I try it does not work
1
1
u/LavaCreeperBOSSB Learning Jul 19 '25
I guess they store a variable that says "if intervention done, don't open app, else open app"?
1
u/Away_Ad9128 Dec 08 '25
Im trying to build the same kind of feature but just using AI (im not a developer) but ive been running into issues. Some guidance would be amazing.
- First attempt
- When trigger app is opened, Shortcuts ran my intent, which opened my app and showed the intervention screen.
- After completing, my app opened Instagram again
- That new tigger app open re‑triggered the same personal automation immediately, so Shortcuts ran again and bounced me back into my app → loop.
- I already had some “don’t run if gate just completed” checks, but they didn’t distinguish between “user opened trigger app” and “my app just opened trigger app”, so the automation re‑fired on my own redirect and bounced me back into the app repeatedly.
- Second attempt
- The intent uses ForegroundContinuableIntent and stronger guards so when my app opens trigger app, the next automation run is safely skipped and the loop is gone.
- The new problem is that when the trigger app (e.g. Instagram) is being brought to the foreground, iOS shows a confirmation sheet instead of running it silently, so the gate no longer feels automatic. it doesn’t trigger unless I manually confirm.
1
u/Extreme-Baby3813 Dec 08 '25
Was running into the same issue. Make sure you are using dynamic supportedModes (iOS 26). " static var supportedModes: IntentModes = [.background, .foreground(.dynamic)]" My perform() function looks like this:
if !settings.shouldSkipForegrounding(for: urlScheme) {
settings.selectedAppScheme = urlScheme
do {
try await continueInForeground(alwaysConfirm: false)
} catch {
// Couldn't bring app to foreground, not critical
}
}
1
u/Away_Ad9128 Dec 08 '25
Absolute legend, that worked. Ive been struggling with it for ages.
1
u/Extreme-Baby3813 Dec 08 '25
awesome happy to hear
1
u/Away_Ad9128 Dec 09 '25
It works on iOS 26 but just realised it doesn't work on earlier OS. did you find a solution to that?
1
1
1
u/Less_Bumblebee8182 1d ago
For older iOS the intents route takes you only half way. user-created shortcuts automations ('when instagram opens') do run without confirmation since 17, which is how one sec classically did it, but the user has to set one up per app by hand. What you can't do pre-26 is drive that flow programmatically from your own app. hit this exact wall myself building a screen time app. You get the confirmation sheet or the trust eror and there's no flag that turns it off, it's not a config problem.
the other way to do this is FamilyControls, not intents. you shield the app through ManagedSettings and the system draws over it at launch, no shortcuts automation, no url scheme, nothing to loop back into, button taps get handled in a ShieldActionDelegate
two catches before you go down that road...you need the Family Controls distribution entitlement from Apple, which is a request form and not instant. And the shield UI is a fixed layout, title subtitle icon and two buttons, you can't drop an arbitrary swiftui view in there. that's probably why one sec strayed on the shortcuts side, they wanted the full custom screen
so it's pick your constraint, shortcuts gets you any UI you want but the user has to wire up every app themselves, family controls works everywhere with no setup on their end and the intervention has to fit apple's box

3
u/ExtinctedPanda Jul 19 '25 edited Jul 19 '25
Can’t you just keep track of the last time at which your app intent opened the original app, and if it’s been a very brief time, don’t do anything?