在 swiftUI 中使用 onContinueUserActivity 处理并发症的启动时,ActivityType 是什么
What is the ActivityType when handling the launch of a complication with onContinueUserActivity in swiftUI
我有一个 SwiftUI Apple Watch 应用程序。当用户点击复杂功能时,我想显示适当的视图。我想我可以使用 onContinueUserActivity 修饰符来做到这一点,但我找不到合适的 ActivityType。
我在下面将其命名为 CLKComplicationTapActivityType
,但我需要实常数。
struct ContentView: View {
var body: some View {
StationList()
.onContinueUserActivity(CLKComplicationTapActivityType, perform: handleComplicationTap)
}
func handleComplicationTap(_ userAcivity: NSUserActivity){
if let date = userAcivity.userInfo?[CLKLaunchedTimelineEntryDateKey]{
\ handle the tap
}
}
}
见https://developer.apple.com/documentation/clockkit/clkcomplicationdescriptor/3612140-useractivity
When the user taps on a complication specified by this configuration,
the system launches the app and calls handle(_:), passing the user
activity.
您可以定义自己的自定义activity:
let YourActivity = NSUserActivity(activityType: "com.foo.customconstant")
然后分配给CLKComplicationDataSource.getComplicationDescriptors(handler:)
中CLKComplicationDescriptor
的userActivity
属性。
我有一个 SwiftUI Apple Watch 应用程序。当用户点击复杂功能时,我想显示适当的视图。我想我可以使用 onContinueUserActivity 修饰符来做到这一点,但我找不到合适的 ActivityType。
我在下面将其命名为 CLKComplicationTapActivityType
,但我需要实常数。
struct ContentView: View {
var body: some View {
StationList()
.onContinueUserActivity(CLKComplicationTapActivityType, perform: handleComplicationTap)
}
func handleComplicationTap(_ userAcivity: NSUserActivity){
if let date = userAcivity.userInfo?[CLKLaunchedTimelineEntryDateKey]{
\ handle the tap
}
}
}
见https://developer.apple.com/documentation/clockkit/clkcomplicationdescriptor/3612140-useractivity
When the user taps on a complication specified by this configuration, the system launches the app and calls handle(_:), passing the user activity.
您可以定义自己的自定义activity:
let YourActivity = NSUserActivity(activityType: "com.foo.customconstant")
然后分配给CLKComplicationDataSource.getComplicationDescriptors(handler:)
中CLKComplicationDescriptor
的userActivity
属性。