Skip to content

Commit 4a8f28f

Browse files
committed
fix(feedback): update docs with SwiftUI notes
1 parent 9f4a974 commit 4a8f28f

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

docs/platforms/apple/common/user-feedback/configuration/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The following options can be configured for the integration in `SentryUserFeedba
5757
| Option | Type | Default | Description |
5858
| ---------------- | ------------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5959
| `location` | `[NSDirectionalRectEdge]` | `[.bottom, .trailing]` | The location of the widget on the screen. |
60-
| `autoInject` | `Bool` | `true` | Injects the Feedback widget into the application when the integration is added. Set `autoInject: false` if you want to call `feedback.attachTo()` or `feedback.openDialog()` directly, or only want to show the widget on certain views. |
60+
| `autoInject` | `Bool` | `true` | Injects the Feedback widget into the application when the integration is added. Set `autoInject: false` if you want to call `SentrySDK.feedback.showWidget()` directly, e.g. to show the widget on certain views. |
6161
| `windowLevel` | `UIWindow.Level` | `UIWindow.Level.normal + 1` | The window level of the widget. |
6262
| `showIcon` | `Bool` | `true` | Whether to show the widget icon. |
6363
| `labelText` | `String?` | `"Report a Bug"` | The text of the widget label. If `nil`, then only the icon is shown. It is an error to set both `labelText` to `nil` and `showIcon` to `false`. |

docs/platforms/apple/common/user-feedback/index.mdx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,92 @@ To start using the User Feedback widget in your Cocoa application, provide a fee
4545

4646
This setup will insert the widget into your app's view hierarchy. By default, it appears in the bottom trailing corner of the screen, but you can fully customize its appearance and behavior.
4747

48+
#### SwiftUI
49+
50+
SwiftUI apps cannot currently use automatic injection of the widget upon SDK start. Several options exist to display the feedback form:
51+
52+
##### Use your own button
53+
54+
Place a `UIButton` somewhere in your app, then provide the reference to the feedback configuration in the options provided on SDK start:
55+
56+
```swift
57+
import Sentry
58+
import SwiftUI
59+
import UIKit
60+
61+
@main
62+
struct SwiftUIApp: App {
63+
// a button displayed somewhere in your app
64+
public let feedbackButton = {
65+
let button = UIButton(type: .custom)
66+
button.setTitle("BYOB Feedback", for: .normal)
67+
return button
68+
}()
69+
70+
init() {
71+
// start the SentrySDK as usual, as early as possible in your app's launch sequence
72+
SentrySDK.start { options in
73+
options.configureFeedback { config in
74+
config.customButton = feedbackButton
75+
}
76+
77+
// your other SDK options
78+
}
79+
}
80+
}
81+
```
82+
83+
##### Manually display the widget from a connected `UIWindowSceneDelegate`
84+
85+
You must set up a `UIApplicationDelegateAdapter`, connect a `UIScene` to your app, and manually call `SentrySDK.feedback.showWidget()`:
86+
87+
```swift
88+
import Sentry
89+
import SwiftUI
90+
91+
@main
92+
struct SwiftUIApp: App {
93+
@UIApplicationDelegateAdaptor private var appDelegate: MyAppDelegate
94+
95+
init() {
96+
// start the SentrySDK as usual, as early as possible in your app's launch sequence
97+
SentrySDK.start { options in
98+
// configure feedback and any other SDK options
99+
}
100+
}
101+
102+
var body: some Scene {
103+
WindowGroup {
104+
ContentView()
105+
}
106+
}
107+
}
108+
109+
class MyAppDelegate: NSObject, UIApplicationDelegate, ObservableObject {
110+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
111+
let configuration = UISceneConfiguration(
112+
name: nil,
113+
sessionRole: connectingSceneSession.role)
114+
if connectingSceneSession.role == .windowApplication {
115+
configuration.delegateClass = MySceneDelegate.self
116+
}
117+
return configuration
118+
}
119+
}
120+
121+
class MySceneDelegate: NSObject, UIWindowSceneDelegate, ObservableObject {
122+
var initializedSentry = false
123+
func sceneDidBecomeActive(_ scene: UIScene) {
124+
guard !initializedSentry else { return }
125+
126+
// display the feedback widget
127+
SentrySDK.feedback.showWidget()
128+
129+
initializedSentry = true
130+
}
131+
}
132+
```
133+
48134
### Session Replay
49135

50136
The User Feedback widget integrates seamlessly with Session Replay. When the widget is opened, the Replay SDK buffers up to 30 seconds of the user's session. If feedback is submitted, this replay is sent along with the feedback, allowing you to view both the feedback and the user's actions leading up to the feedback submission.

0 commit comments

Comments
 (0)