iOS14后SwiftUI下使用NSUserActivity


2年前 1002次点击 来自 移动端

标签: 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)
}

Made with in Shangrao,China By Devler.

Copyright © Devler 2012 - 2022

赣ICP备19009883号-1