前言
关于 iOS 的 home screen quick action,想尝试一下,于是在翻阅了一些资料后,简单实现了一下
实现
核心方法是 application(_:performActionFor:completionHandler:)
参考代码
1 2 3 4 5 6 7 8 9 10
| func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { print(shortcutItem.type) let alertVC = UIAlertController(title: shortcutItem.type, message: shortcutItem.type, preferredStyle: .alert) UIApplication.shared .connectedScenes .map({$0 as? UIWindowScene}) .compactMap({$0}).first?.windows.first? .rootViewController? .present(alertVC, animated: true, completion: nil) }
|
demo
参考
Add Home Screen Quick Actions
Quick Actions in iOS