Skip to content

Commit

Permalink
fix headerdoc in SentrySDK.h; use new SDK capture method in form subm…
Browse files Browse the repository at this point in the history
…ission
  • Loading branch information
armcknight committed Nov 16, 2024
1 parent 13b0327 commit eea1f96
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 31 deletions.
34 changes: 22 additions & 12 deletions Sources/Sentry/Public/SentrySDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@

@protocol SentrySpan;

@class SentryOptions, SentryEvent, SentryBreadcrumb, SentryScope, SentryUser, SentryId,
SentryUserFeedback, SentryTransactionContext;
@class SentryBreadcrumb;
@class SentryEvent;
@class SentryFeedback;
@class SentryId;
@class SentryMetricsAPI;
@class UIView;
@class SentryOptions;
@class SentryReplayApi;
@class SentryScope;
@class SentryTransactionContext;
@class SentryUser;
@class SentryUserFeedback;
@class UIView;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -246,25 +253,28 @@ SENTRY_NO_INIT
/**
* Captures user feedback that was manually gathered and sends it to Sentry.
* @param userFeedback The user feedback to send to Sentry.
* @note This method will be deprecated in a future release; use `captureFeedback` instead.
*/
+ (void)captureUserFeedback:(SentryUserFeedback *)userFeedback
NS_SWIFT_NAME(capture(userFeedback:));

/**
* Captures user feedback that was manually gathered and sends it to Sentry.
* @param feedback The feedback to send to Sentry.
* @note If you'd prefer not to have to build the UI required to gather the feedback from the user,
* consider using `showUserFeedbackForm`, which delivers a prepackaged user feedback experience. See
* @c SentryOptions.configureUserFeedback to customize a fully managed integration. See
* https://docs.sentry.io/platforms/apple/user-feedback/#user-feedback-api and (TODO: add link to
* new docs) for more information on each approach.
* https://docs.sentry.io/platforms/apple/user-feedback/ for more information.
*/
+ (void)captureUserFeedback:(SentryUserFeedback *)userFeedback
NS_SWIFT_NAME(capture(userFeedback:));
+ (void)captureFeedback:(SentryFeedback *)feedback NS_SWIFT_NAME(capture(feedback:));

/**
* Display a form to gather information from an end user in the app to send to Sentry as a user
* feedback event.
* @see @c SentryOptions.enableUserFeedbackIntegration and @c SentryOptions.configureUserFeedback to
* enable the functionality and customize the experience.
* @note If @c SentryOptions.enableUserFeedbackIntegration is @c NO, this method is a no-op.
* @see @c SentryOptions.configureUserFeedback to customize the experience.
* @note This is a fully managed user feedback flow; there will be no need to call
* @c SentrySDK.captureUserFeedback . See
* https://docs.sentry.io/platforms/apple/user-feedback/#user-feedback-api and (TODO: add link to
* new docs) for more information on each approach.
* https://docs.sentry.io/platforms/apple/user-feedback/ for more information.
*/
+ (void)showUserFeedbackForm;

Expand Down
12 changes: 11 additions & 1 deletion Sources/Sentry/Public/SentryUserFeedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ NS_ASSUME_NONNULL_BEGIN
*/
NS_SWIFT_NAME(UserFeedback)
@interface SentryUserFeedback : NSObject <SentrySerializable>
SENTRY_NO_INIT

/**
* Initializes SentryUserFeedback and sets the required eventId.
* @param eventId The eventId of the event to which the user feedback is associated.
* @note Uses the old envelope format descried at
* https://develop.sentry.dev/sdk/data-model/envelope-items/#user-feedback and will be deprecated in
* the future.
*/
- (instancetype)initWithEventId:(SentryId *)eventId;

/**
* Initializes a new `SentryUserFeedback` as its own event, instead of one attached to a transaction
* or error event.
* @note Uses the new envelope format described at
* https://develop.sentry.dev/application/feedback-architecture/#feedback-events.
*/
- (instancetype)init;

/**
* The eventId of the event to which the user feedback is associated.
*/
Expand Down
40 changes: 33 additions & 7 deletions Sources/Sentry/SentryUserFeedback.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@
#import "SentrySwift.h"
#import <Foundation/Foundation.h>

@implementation SentryUserFeedback
typedef enum : NSUInteger {
/** A user feedback attached to a transaction or error event. */
kSentryUserFeedbackTypeAttached,

/** A user feedback sent as its own event independent of any other event. */
kSentryUserFeedbackTypeStandalone,
} SentryUserFeedbackType;

@implementation SentryUserFeedback {
SentryUserFeedbackType _type;
}

- (instancetype)init {
if (self = [super init]) {
_type = kSentryUserFeedbackTypeStandalone;
_eventId = [[SentryId alloc] init];
}
return self;
}

- (instancetype)initWithEventId:(SentryId *)eventId
{
Expand All @@ -11,18 +29,26 @@ - (instancetype)initWithEventId:(SentryId *)eventId
_email = @"";
_name = @"";
_comments = @"";
_type = kSentryUserFeedbackTypeAttached;
}
return self;
}

- (NSDictionary<NSString *, id> *)serialize
{
return @{
@"event_id" : self.eventId.sentryIdString,
@"email" : self.email,
@"name" : self.name,
@"comments" : self.comments
};
switch (_type) {
case kSentryUserFeedbackTypeAttached:
return @{
@"event_id" : self.eventId.sentryIdString,
@"email" : self.email,
@"name" : self.name,
@"comments" : self.comments
};
case kSentryUserFeedbackTypeStandalone:
return @{

};
}
}

@end
1 change: 1 addition & 0 deletions Sources/Sentry/include/SentryPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "SentryNSDataUtils.h"
#import "SentryRandom.h"
#import "SentryTime.h"
#import "SentrySDK+Private.h"

// Headers that also import SentryDefines should be at the end of this list
// otherwise it wont compile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SentryFeedback: NSObject, SentrySerializable {
/// The event id that this feedback is associated with, like a crash report.
var associatedEventId: String?

init(name: String?, email: String?, message: String, hints: [String: Any]?, source: Source, associatedEventId: String?) {
init(name: String?, email: String?, message: String, hints: [String: Any]? = nil, source: Source = .widget, associatedEventId: String? = nil) {
self.eventId = SentryId()
self.name = name
self.email = email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,8 @@ class SentryUserFeedbackForm: UIViewController {
}

func submitFeedbackButtonTapped() {
guard let name = fullNameTextField.text, let email = emailTextField.text else {
return
}
let error = NSError(domain: "user-feedback", code: 1)
let eventId = SentrySDK.capture(error: error)
let uf = UserFeedback(eventId: eventId)
uf.name = name
uf.email = email
uf.comments = messageTextView.text
SentrySDK.capture(userFeedback: uf)
let feedback = SentryFeedback(name: fullNameTextField.text, email: emailTextField.text, message: messageTextView.text, hints: nil)
SentrySDK.capture(feedback: feedback)
delegate?.finished()
}

Expand Down

0 comments on commit eea1f96

Please sign in to comment.