In Swift, I need to detect when a person faucets my widget to open the app, so I can ship analytics. Nevertheless, I would like the analytics to be despatched immediately from the widget, not from the app itself. This implies I don’t need to use SwiftUI’s onOpenURL
.
To realize this, I attempted including a transparent button that calls an AppIntent
like this:
var physique: some View {
ZStack {
Button(intent: TappIntent()) {
ZStack {
Shade.clear
}
}
.body(maxWidth: .infinity, maxHeight: .infinity)
.buttonBorderShape(.automated)
.buttonStyle(NoHighlightButtonStyle())
}
}
public struct TappIntent: AppIntent {
public static var title: LocalizedStringResource = "Did Faucet Widget"
public func carry out() async throws -> some IntentResult & OpensIntent {
print("TouchIntent was referred to as", degree: .INFO)
SharedAnalytics(sort: "Widget").occasion("Common Faucet")
return .outcome(opensIntent: OpenAppIntent())
}
}
The issue is that each time this AppIntent
is known as, it additionally triggers getTimeline
, which I don’t need.
My questions:
- Is there a greater approach to detect when a person faucets a widget with out triggering getTimeline?
- Is there a approach to configure an AppIntent in order that calling it doesn’t refresh the widget timeline?