我已经解决了所有其他问题,但我不知道出了什么问题。我从 Apple 开发者网站Add Home Screen Quick Actions下载了示例项目,这没问题,但是当我开始一个新的 Xcode 项目并复制它时,它对我不起作用。我肯定错过了什么。在这一点上,我只想让它在控制台中打印说“按下快捷键”。当我添加print("Shortcut pressed")
到我下载的 Apple 项目时,它工作正常。
在这一点上,我只是在尝试随机的东西。
我用一个数组、一个字典和字符串更新了我的 info.plist,我只是复制并过去了这些值,以免出现任何拼写错误。
UIApplicationShortcutItems, 项目 0, UIApplicationShortcutItemType, UIApplicationShortcutItemIconType, UIApplicationShortcutItemTitle
按下应用程序图标时会出现快捷方式,但它只是打开应用程序。
这是我非常基本的 AppDelegate.Swift 文件,只是试图让它做任何事情可能是我的项目设置,我的 Xcode 版本是最新的 - 版本 11.1 (11A1027)
我以前从未使用过快速操作,它接缝很简单,但接缝很简单,只需在 plist 中添加一些行并将一些代码添加到 AppDelegate.Swift 文件中,但需要很长时间才能开始工作。
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var shortcutItemToProcess: UIApplicationShortcutItem?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if let shortcutItem = launchOptions?[UIApplication.LaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
shortcutItemToProcess = shortcutItem
print("Shortcut pressed")
}
return true
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
print("Shortcut pressed")
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("Shortcut pressed")
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
谢谢你。