Skip to content

Commit 5e5d875

Browse files
authored
feat: Expose attachment type on SentryAttachment (#6521)
* chore: Restore PrivateSentrySDKOnlyTests * feat: Add view hierarchy attachment support for downstream SDKs * Remove `addViewHierarchyAttachment` from `PrivateSentrySDKOnly` * Update test * Expose attachment type on `SentryAttachment` * Update changelog * Undo merge conflict * Run generate api * Update SentryAttachment docs
1 parent 5b90eb2 commit 5e5d875

File tree

4 files changed

+462
-42
lines changed

4 files changed

+462
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
### Improvements
7171

7272
- Replace deprecated SCNetworkReachability with NWPathMonitor (#6019)
73+
- Expose attachment type on `SentryAttachment` for downstream SDKs (like sentry-godot) (#6521)
7374
- Increase attachment max size to 100MB (#6537)
7475

7576
## 8.57.1

Sources/Sentry/Public/SentryAttachment.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88

99
NS_ASSUME_NONNULL_BEGIN
1010

11+
/**
12+
* Attachment Type
13+
*
14+
* This enum specifies the type of attachment. The attachment type is primarily used by downstream
15+
* SDKs (such as sentry-godot) to distinguish between different attachment categories.
16+
* Most applications using the SDK directly do not need to specify this, as the default
17+
* @c kSentryAttachmentTypeEventAttachment is used for regular file attachments.
18+
*
19+
*
20+
* See also: https://develop.sentry.dev/sdk/data-model/envelope-items/#attachment
21+
*/
22+
typedef NS_ENUM(NSInteger, SentryAttachmentType) {
23+
/**
24+
* Standard event attachment. This is the default type for user-provided attachments.
25+
*/
26+
kSentryAttachmentTypeEventAttachment,
27+
/**
28+
* View hierarchy attachment. Automatically set by the SDK when capturing view hierarchy data.
29+
* This type is primarily used by downstream SDKs.
30+
*/
31+
kSentryAttachmentTypeViewHierarchy
32+
};
33+
1134
/**
1235
* You can use an attachment to store additional files alongside an event.
1336
*/
@@ -62,6 +85,30 @@ SENTRY_NO_INIT
6285
filename:(NSString *)filename
6386
contentType:(nullable NSString *)contentType;
6487

88+
/**
89+
* Initializes an attachment with data.
90+
* @param data The data for the attachment.
91+
* @param filename The name of the attachment to display in Sentry.
92+
* @param contentType The content type of the attachment. Default is @c "application/octet-stream".
93+
* @param attachmentType The type of the attachment. Default is @c "EventAttachment".
94+
*/
95+
- (instancetype)initWithData:(NSData *)data
96+
filename:(NSString *)filename
97+
contentType:(nullable NSString *)contentType
98+
attachmentType:(SentryAttachmentType)attachmentType;
99+
100+
/**
101+
* Initializes an attachment with data.
102+
* @param path The path of the file whose contents you want to upload to Sentry.
103+
* @param filename The name of the attachment to display in Sentry.
104+
* @param contentType The content type of the attachment. Default is @c "application/octet-stream".
105+
* @param attachmentType The type of the attachment. Default is@c "EventAttachment".
106+
*/
107+
- (instancetype)initWithPath:(NSString *)path
108+
filename:(NSString *)filename
109+
contentType:(nullable NSString *)contentType
110+
attachmentType:(SentryAttachmentType)attachmentType;
111+
65112
/**
66113
* The data of the attachment.
67114
*/
@@ -82,6 +129,11 @@ SENTRY_NO_INIT
82129
*/
83130
@property (readonly, nonatomic, copy, nullable) NSString *contentType;
84131

132+
/**
133+
* The type of the attachment.
134+
*/
135+
@property (readonly, nonatomic) SentryAttachmentType attachmentType;
136+
85137
@end
86138

87139
NS_ASSUME_NONNULL_END

Sources/Sentry/include/SentryAttachment+Private.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,8 @@ NS_ASSUME_NONNULL_BEGIN
66
FOUNDATION_EXPORT NSString *const kSentryAttachmentTypeNameEventAttachment;
77
FOUNDATION_EXPORT NSString *const kSentryAttachmentTypeNameViewHierarchy;
88

9-
/**
10-
* Attachment Type
11-
*/
12-
typedef NS_ENUM(NSInteger, SentryAttachmentType) {
13-
kSentryAttachmentTypeEventAttachment,
14-
kSentryAttachmentTypeViewHierarchy
15-
};
16-
179
NSString *nameForSentryAttachmentType(SentryAttachmentType attachmentType);
1810

1911
SentryAttachmentType typeForSentryAttachmentName(NSString *_Nullable name);
2012

21-
@interface SentryAttachment ()
22-
SENTRY_NO_INIT
23-
24-
/**
25-
* Initializes an attachment with data.
26-
* @param data The data for the attachment.
27-
* @param filename The name of the attachment to display in Sentry.
28-
* @param contentType The content type of the attachment. Default is @c "application/octet-stream".
29-
* @param attachmentType The type of the attachment. Default is @c "EventAttachment".
30-
*/
31-
- (instancetype)initWithData:(NSData *)data
32-
filename:(NSString *)filename
33-
contentType:(nullable NSString *)contentType
34-
attachmentType:(SentryAttachmentType)attachmentType;
35-
36-
/**
37-
* Initializes an attachment with data.
38-
* @param path The path of the file whose contents you want to upload to Sentry.
39-
* @param filename The name of the attachment to display in Sentry.
40-
* @param contentType The content type of the attachment. Default is @c "application/octet-stream".
41-
* @param attachmentType The type of the attachment. Default is@c "EventAttachment".
42-
*/
43-
- (instancetype)initWithPath:(NSString *)path
44-
filename:(NSString *)filename
45-
contentType:(nullable NSString *)contentType
46-
attachmentType:(SentryAttachmentType)attachmentType;
47-
48-
/**
49-
* The type of the attachment.
50-
*/
51-
@property (readonly, nonatomic) SentryAttachmentType attachmentType;
52-
53-
@end
54-
5513
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)