Close Menu
geekfence.comgeekfence.com
    What's Hot

    ChatGPT Now Integrated to PhonePe

    November 13, 2025

    The Download: How to survive a conspiracy theory, and moldy cities

    November 13, 2025

    4 Goal Setting Methods to Identify Untapped Opportunities

    November 13, 2025
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»iOS Development»Integrating Siri Shortcuts into SwiftUI Apps with App Intents
    iOS Development

    Integrating Siri Shortcuts into SwiftUI Apps with App Intents

    AdminBy AdminOctober 31, 2025No Comments6 Mins Read1 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Integrating Siri Shortcuts into SwiftUI Apps with App Intents
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Have you ever wondered how to make your app’s features accessible from the built-in Shortcuts app on iOS? That’s what the App Intents framework is designed for. Introduced in iOS 16 and macOS Ventura, the framework has been around for over two years. It provides developers with a powerful way to define actions that users can trigger through Shortcuts. With App Intents, your app can integrate seamlessly with the Shortcuts app, Siri, and even system-wide Spotlight search.

    In this tutorial, we’ll explore how to use the App Intents framework to bring your app’s functionality into Shortcuts by creating an App Shortcut. Using the Ask Me Anything app as our example, we’ll walk through the process of letting users ask questions right from Shortcuts.

    This tutorial assumes you’re familiar with the Ask Me Anything app from our Foundation Models tutorial. If you haven’t read it yet, please review that tutorial first.

    Using App Intents

    The Ask Me Anything app allows users to ask questions and then it provides answers using the on-device LLM. What we are going to do is to expose this feature to the Shortcuts app. To do that, all you need to do is to create a new Struct and adopt the App Intents framework.

    Let’s create a new file named AskQuestionIntent in the AskMeAnything project and update its content like below:

    import SwiftUI
    import AppIntents
    
    struct AskQuestionIntent: AppIntent {
        static var title: LocalizedStringResource = "Ask Question"
        static var description = IntentDescription("Ask a question to get an AI-powered answer")
        
        static let supportedModes: IntentModes = .foreground
        
        @Parameter(title: "Question", description: "The question you want to ask")
        var question: String
        
        @AppStorage("incomingQuestion") var storedQuestion: String = ""
        
        init() {}
        
        init(question: String) {
            self.question = question
        }
        
        func perform() async throws -> some IntentResult {
            storedQuestion = question
            
            return .result()
        }
    }
    
    

    The code above defines a struct called AskQuestionIntent, which is an App Intent using the AppIntents framework. An App Intent is basically a way for your app to “talk” to the Shortcuts app, Siri, or Spotlight. Here, the intent’s job is to let a user ask a question and get an AI-powered answer.

    At the top, we have two static properties: title and description. These are what the Shortcuts app or Siri will show the user when they look at this intent.

    The supportedModes property specifies that this intent can only run in the foreground, meaning the app will open when the shortcut is executed.

    The @Parameter property wrapper defines the input the user needs to give. In this case, it’s a question string. When someone uses this shortcut, they’ll be prompted to type or say this question.

    The @AppStorage("incomingQuestion") property is a convenient way to persist the provided question in UserDefaults, making it accessible to other parts of the app.

    Finally, the perform() function is where the intent actually does its work. In this example, it just takes the question from the parameter and saves it into storedQuestion. Then it returns a .result() to tell the system it’s done. You’re not doing the AI call directly here — just passing the question into your app so it can handle it however it wants.

    Handling the Shortcut

    Now that the shortcut is ready, executing the “Ask Question” shortcut will automatically launch the app. To handle this behavior, we need to make a small update to ContentView.

    First, declare a variable to retrieve the question provided by the shortcut like this:

    @AppStorage("incomingQuestion") private var incomingQuestion: String = ""

    Next, attach the onChange modifier to the scroll view:

    ScrollView {
    
    ...
    
    
    }
    .onChange(of: incomingQuestion) { _, newQuestion in
        if !newQuestion.isEmpty {
            question = newQuestion
            incomingQuestion = ""
            
            Task {
                await generateAnswer()
            }
        }
    }

    In the code above, we attach an .onChange modifier to the ScrollView so the view can respond whenever the incomingQuestionvalue is updated. Inside the closure, we check whether a new question has been received from the shortcut. If so, we trigger the generateAnswer() method, which sends the question to the on-device LLM for processing and returns an AI-generated answer.

    Adding a Preconfigured Shortcut

    In essence, this is how you create a shortcut that connects directly to your app. If you’ve explored the Shortcuts app before, you’ve probably noticed that many apps already provide preconfigured shortcuts. For instance, the Calendar app includes ready-made shortcuts for creating and managing events.

    Preconfigured app shortcuts

    With the App Intents framework, adding these preconfigured shortcuts to your own app is straightforward. They can be used right away in the Shortcuts app or triggered hands-free with Siri. Building on the AskQuestionIntent we defined earlier, we can now create a corresponding shortcut so users can trigger it more easily. For example, here’s how we could define an “Ask Question” shortcut:

    struct AskQuestionShortcut: AppShortcutsProvider {
        static var appShortcuts: [AppShortcut] {
            AppShortcut(
                intent: AskQuestionIntent(),
                phrases: [
                    "Ask \(.applicationName) a question",
                    "Ask \(.applicationName) about \(.applicationName)",
                    "Get answer from \(.applicationName)",
                    "Use \(.applicationName)"
                ],
                shortTitle: "Ask Question",
                systemImageName: "questionmark.bubble"
            )
        }
    }
    

    The AskQuestionShortcut adopts the AppShortcutsProvider protocol, which is how we tell the system what shortcuts our app supports. Inside, we define a single shortcut called “Ask Question,” which is tied to our AskQuestionIntent. We also provide a set of example phrases that users might say to Siri, such as “Ask [App Name] a question” or “Get answer from [App Name].”

    Finally, we give the shortcut a short title and a system image name so it’s visually recognizable inside the Shortcuts app. Once this code is in place, the system automatically registers it, and users will see the shortcut ready to use—no extra setup required.

    Testing the Shortcut

    Shortcuts in Shortcuts app and Spotlight Search

    To give the shortcut a try, build and run the app on either the simulator or a physical iOS device. Once the app has launched at least once, return to the Home Screen and open the Shortcuts app. You should now find the “Ask Question” shortcut we just created, ready for you to use.

    The new shortcut not only appears in the Shortcuts app but is also available in Spotlight search.

    When you run the “Ask Question” shortcut, it should automatically prompt you for question. Once you type your question and tap Done, it brings up the app and show you the answer.

    shortcut-demo-homescreen.png

    Summary

    In this tutorial, we explored how to use the App Intents framework to expose your app’s functionality to the Shortcuts app and Siri. We walked through creating an AppIntent to handle user input, defining a preconfigured shortcut, and testing it right inside the Shortcuts app. With this setup, users can now ask questions to the Ask Me Anything app directly from Shortcuts or via Siri, making the experience faster and more convenient.

    In the next tutorial, we’ll take it a step further by showing you how to display the AI’s answer in a Live Activity. This will let users see their responses in real time, right on the Lock Screen or in the Dynamic Island—without even opening the app.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Introducing SwiftMCP | Cocoanetics

    November 13, 2025

    File upload using Vapor 4

    November 12, 2025

    SwiftUI can’t have working rounded corners with AsyncImage and ultra-wide images

    November 11, 2025

    Transitions in SwiftUI · objc.io

    November 10, 2025

    Keyboard shortcuts for Export Unmodified Original in Photos for Mac – Ole Begemann

    November 9, 2025

    Using Tool Calling to Supercharge Foundation Models

    November 8, 2025
    Top Posts

    Microsoft 365 Copilot now enables you to build apps and workflows

    October 29, 20256 Views

    Here’s the latest company planning for gene-edited babies

    November 2, 20254 Views

    Skills, Roles & Career Guide

    November 4, 20252 Views
    Don't Miss

    ChatGPT Now Integrated to PhonePe

    November 13, 2025

    ChatGPT, a globally recognised AI (artificial intelligence) platform, will now be integrated on PhonePe. ChatGPT…

    The Download: How to survive a conspiracy theory, and moldy cities

    November 13, 2025

    4 Goal Setting Methods to Identify Untapped Opportunities

    November 13, 2025

    Google’s €5.5B Germany investment reshapes enterprise cloud

    November 13, 2025
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    ChatGPT Now Integrated to PhonePe

    November 13, 2025

    The Download: How to survive a conspiracy theory, and moldy cities

    November 13, 2025

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2025 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.