Thursday, May 21, 2026
HomeiOS Developmentswiftui - Implementing a static fast motion in iOS

swiftui – Implementing a static fast motion in iOS

[ad_1]

I am attempting to implement a easy static fast motion “New Jot”. I have been studying about fast motion and the distinction between static and dynamic, and since this motion in my app by no means adjustments, I went with a static.

Following up the instructions of a number of posts (this one and this one), I created the next:

Step 1. added the static fast motion merchandise:

enter image description here

Step 2. created an app delegate:

import UIKit

remaining class AppDelegate: UIResponder, UIApplicationDelegate {
    func utility(
        _ utility: UIApplication,
        configurationForConnecting connectingSceneSession: UISceneSession,
        choices: UIScene.ConnectionOptions
    ) -> UISceneConfiguration {
        let configuration = UISceneConfiguration(
        title: "Major Scene",
        sessionRole: connectingSceneSession.position
        )
        configuration.delegateClass = MainSceneDelegate.self
        return configuration
    }
}

And added it to the @fundamental struct

@UIApplicationDelegateAdaptor non-public var appDelegate: AppDelegate

Step 3. created a fundamental scene delegate:

import SwiftUI
import UIKit

remaining class MainSceneDelegate: UIResponder, UIWindowSceneDelegate {
    @Setting(.openURL) non-public var openURL: OpenURLAction

    func scene(
        _ scene: UIScene,
        willConnectTo session: UISceneSession,
        choices connectionOptions: UIScene.ConnectionOptions
    ) {
        guard let shortcutItem = connectionOptions.shortcutItem else {
        return
        }

        handleShortcutItem(shortcutItem)
    }

    func windowScene(
        _ windowScene: UIWindowScene,
        performActionFor shortcutItem: UIApplicationShortcutItem,
        completionHandler: @escaping (Bool) -> Void
    ) {
        handleShortcutItem(shortcutItem, completionHandler: completionHandler)
    }

    non-public func handleShortcutItem(
        _ shortcutItem: UIApplicationShortcutItem,
        completionHandler: ((Bool) -> Void)? = nil
    ) {
        guard shortcutItem.kind == "NewJot" else {
            completionHandler!(false)
            return
        }

        openURL(URL(string: "NewJot")!) { accomplished in
            print("DEBUG worth: " + accomplished.description)
            completionHandler!(accomplished)
        }
    }
}

Step 4. attempt to execute code when the consumer faucets on the fast motion:

.onOpenURL { url in
         guard url.path == "/NewJot" else {
               print("DEBUG Return!")
               return
         }
                                
         isNew = true
         self.sheetNewNote.toggle()
}

Here is what occurs:

When the app is working, and I ship it to the background and I faucet the fast motion, it will get to the scene delegate openURL(URL(string: "NewJot")!), however nothing else.

When the app is just not working and I faucet the fast motion, the app opens and crashes.

I went again to google and search some extra. Each instance I discovered simply reveals me the identical or comparable code to the one I posted right here.
What am I lacking? How do you implement a static fast motion?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments