iOS14后SwiftUI下使用NSUserActivity

1个月前 78次点击 来自 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
开发者雷

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

本站文章全部采用 CC BY 4.0 协议,欢迎转载

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