Skip to content

Instantly share code, notes, and snippets.

@mfcollins3
Last active January 10, 2021 02:07
Show Gist options
  • Save mfcollins3/76dd8cd29b1444f959699e422790eda1 to your computer and use it in GitHub Desktop.
Save mfcollins3/76dd8cd29b1444f959699e422790eda1 to your computer and use it in GitHub Desktop.
import UIKit
final class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
let configuration = UISceneConfiguration(
name: "Main Scene",
sessionRole: connectingSceneSession.role
)
configuration.delegateClass = MainSceneDelegate.self
return configuration
}
}
import SwiftUI
struct ContentView: View {
@State private var showComposeView = false
var body: some View {
Text("Hello, world!")
.padding
.alert(isPresented: $showComposeView) {
Alert(
title: Text("Compose Note"),
message: Text("TODO: Compose a note"),
primaryButton: .default(Text("Create")),
secondaryButton: .cancel()
)
}
.onOpenURL { url in
guard url.path == "/createNote" else {
return
}
showComposeView = true
}
}
}
import SwiftUI
import UIKit
final class MainSceneDelegate: UIResponder, UIWindowSceneDelegate {
@Environment(\.openURL) private var openURL: OpenURLAction
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionptions: 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)
}
private func handleShortcutItem(
_ shortcutItem: UIApplicationShortcutItem,
completionHandler: ((Bool) -> Void)? = nil
) {
guard shortcutItem.type == "me.michaelfcollins3.QuickActionDemo.CreateNoteAction" else {
completionHandler(false)
return
}
openURL(URL(string: "quickactiondemo://actions/createNote")!) { completed in
completionHandler(completed
}
}
}
import SwiftUI
@main
struct QuickActionDemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
import SwiftUI
@main
struct QuickActionDemoApp: App {
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment