我浏览了所有其他的问题,但我无法弄清楚出了什么问题。我从Apple Developer网站下载了示例项目添加主屏幕快速操作,那个没有问题,但是当我启动一个新的Xcode项目并复制它时,它对我不起作用。我一定漏掉了什么东西。现在,我只想让它在控制台中打印“按下快捷方式”。当我在我下载的Apple项目中添加
目前我只是随意尝试各种东西。
我已经使用数组、字典和字符串更新了我的info.plist,并复制和粘贴了值,以免出现任何拼写错误。
UIApplicationShortcutItems,Item 0,UIApplicationShortcutItemType,UIApplicationShortcutItemIconType,UIApplicationShortcutItemTitle 按下应用程序图标时,这个快捷方式出现了,但它只是打开了应用程序。
这是我的非常基本的AppDelegate.Swift文件,只是试图让它做任何事情。可能是我的项目设置有问题,我的Xcode版本是最新的 - 版本11.1(11A1027)
我以前从未使用过快捷操作,它似乎很简单,只需在plist中添加几行代码,并在AppDelegate.Swift文件中添加一些代码,但是要使其正常工作需要很长时间。
print(“Shortcut pressed”)
时,它可以正常工作。目前我只是随意尝试各种东西。
我已经使用数组、字典和字符串更新了我的info.plist,并复制和粘贴了值,以免出现任何拼写错误。
UIApplicationShortcutItems,Item 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.
}
}
谢谢。
startAct()
。您是否可以友善地指导我如何从SceneDelegate.swift开始按下快速操作时的方向,因为显然目前它说Use of unresolved identifier 'startAct'
。 - Kurt L.vc = ViewController() vc.startAct()
,但是当它尝试运行startAct()函数时,它崩溃了,并在第一行的startAct()函数上显示了一个红线,提示尝试解包一个可选项。第一行是startButton.isHidden = true
,我猜测它无法从SceneDelegate中找到start button。 - Kurt L.func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
。这将转换为if let shortcutItem = connectionOptions.shortcutItem { shortcutItemToProcess = shortcutItem }
。 - Daisy R.