iOS14后SwiftUI下使用NSUserActivity

5个月前 242次点击 来自 iOS

标签: SwiftUI

iOS14后废弃application(_:continue:restorationHandler:)方法,那么如何继续使用NSUserActivity?

SwiftUI在NSUserActivity的使用上做了更方便的改进,如下:
首先实现handleSpotlight

func handleSpotlight(_ userActivity: NSUserActivity) {
    if let id = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String {
        print("Found identifier \(id)")
    }
}

然后在实现onContinueUserActivity

WindowGroup {
    ContentView()
        .onContinueUserActivity(CSSearchableItemActionType, perform: handleSpotlight)
}
Card image cap
开发者雷

尘世间一个小小的开发者,每天增加一些无聊的知识,就不会无聊了

要加油~~~

技术文档 >> 系列应用 >>
热推应用
Let'sLearnSwift
学习Swift的入门教程
PyPie
Python is as good as Pie
标签