Last active
June 30, 2020 18:02
-
-
Save aheze/d1c5455c5e0ba5531bbe9d4e9a9e6560 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| class AppDelegate: NSObject, UIApplicationDelegate { | |
| @Published var shortcutItemType: String? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { | |
| if let shortcutItem = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem { | |
| if shortcutItem.type == "com.example.ExampleApp.exampleAction" { | |
| shortcutItemType = shortcutItem.type | |
| } | |
| } | |
| return true | |
| } | |
| } | |
| @main | |
| struct SwiftUI_AppApp: App { | |
| @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate | |
| @State var shortcutPressed = false | |
| var body: some Scene { | |
| WindowGroup { | |
| ContentView(shortcutPressed: $shortcutPressed) | |
| .onReceive(appDelegate.$shortcutItemType) { _ in | |
| shortcutPressed = true | |
| } | |
| } | |
| } | |
| } | |
| struct ContentView: View { | |
| @Binding var shortcutPressed: Bool | |
| let defaults = UserDefaults.standard | |
| var body: some View { | |
| if shortcutPressed { | |
| return Text("A quick action was tapped!") | |
| } else { | |
| return Text("Just a normal SwiftUI View!") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment