@@ -20,7 +20,8 @@ import {getWizardInstallSnippet} from 'sentry/utils/gettingStartedDocs/mobileWiz
20
20
21
21
export enum InstallationMode {
22
22
AUTO = 'auto' ,
23
- MANUAL = 'manual' ,
23
+ MANUAL_SWIFT = 'manual-swift' ,
24
+ MANUAL_OBJECTIVE_C = 'manual-objective-c' ,
24
25
}
25
26
26
27
const platformOptions = {
@@ -32,8 +33,12 @@ const platformOptions = {
32
33
value : InstallationMode . AUTO ,
33
34
} ,
34
35
{
35
- label : t ( 'Manual' ) ,
36
- value : InstallationMode . MANUAL ,
36
+ label : t ( 'Manual (Swift)' ) ,
37
+ value : InstallationMode . MANUAL_SWIFT ,
38
+ } ,
39
+ {
40
+ label : t ( 'Manual (Objective-C)' ) ,
41
+ value : InstallationMode . MANUAL_OBJECTIVE_C ,
37
42
} ,
38
43
] ,
39
44
defaultValue : InstallationMode . AUTO ,
@@ -46,14 +51,19 @@ type Params = DocsParams<PlatformOptions>;
46
51
const isAutoInstall = ( params : Params ) =>
47
52
params . platformOptions . installationMode === InstallationMode . AUTO ;
48
53
54
+ const isManualSwift = ( params : Params ) =>
55
+ params . platformOptions . installationMode === InstallationMode . MANUAL_SWIFT ;
56
+
57
+ const selectedLanguage = ( params : Params ) => ( isManualSwift ( params ) ? 'swift' : 'objc' ) ;
58
+
49
59
const getManualInstallSnippet = ( params : Params ) => `
50
60
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "${ getPackageVersion (
51
61
params ,
52
62
'sentry.cocoa' ,
53
63
'8.49.0'
54
64
) } "),`;
55
65
56
- const getConfigurationSnippet = ( params : Params ) => `
66
+ const getConfigurationSnippetSwift = ( params : Params ) => `
57
67
import Sentry
58
68
59
69
// ....
@@ -108,6 +118,58 @@ func application(_ application: UIApplication,
108
118
return true
109
119
}` ;
110
120
121
+ const getConfigurationSnippetObjectiveC = ( params : Params ) => `
122
+ @import Sentry;
123
+
124
+ // ....
125
+
126
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
127
+ [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
128
+ options.dsn = "${ params . dsn . public } ";
129
+ options.debug = YES; // Enabling debug when first installing is always helpful
130
+
131
+ // Adds IP for users.
132
+ // For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
133
+ options.sendDefaultPii = YES;${
134
+ params . isPerformanceSelected
135
+ ? `
136
+
137
+ // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
138
+ // We recommend adjusting this value in production.
139
+ options.tracesSampleRate = @1.0;`
140
+ : ''
141
+ } ${
142
+ params . isProfilingSelected &&
143
+ params . profilingOptions ?. defaultProfilingMode !== 'continuous'
144
+ ? `
145
+
146
+ // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
147
+ // We recommend adjusting this value in production.
148
+ options.tracesSampleRate = @1.0;`
149
+ : params . isProfilingSelected &&
150
+ params . profilingOptions ?. defaultProfilingMode === 'continuous'
151
+ ? `
152
+
153
+ // Configure the profiler to start profiling when there is an active root span
154
+ // For more information, visit: https://docs.sentry.io/platforms/apple/profiling/
155
+ [options setConfigureProfiling:^(SentryProfileOptions * _Nonnull profiling) {
156
+ profiling.lifecycle = SentryProfileLifecycleTrace;
157
+ profiling.sessionSampleRate = 1.0;
158
+ }];`
159
+ : ''
160
+ } ${
161
+ params . isReplaySelected
162
+ ? `
163
+
164
+ // Record Session Replays for 100% of Errors and 10% of Sessions
165
+ options.sessionReplay.onErrorSampleRate = 1.0;
166
+ options.sessionReplay.sessionSampleRate = 0.1;`
167
+ : ''
168
+ }
169
+ }];
170
+ return YES;
171
+ }` ;
172
+
111
173
const getConfigurationSnippetSwiftUi = ( params : Params ) => `
112
174
import Sentry
113
175
@@ -160,15 +222,37 @@ struct SwiftUIApp: App {
160
222
}
161
223
}` ;
162
224
163
- const getVerifySnippet = ( ) => `
164
- let button = UIButton(type: .roundedRect)
165
- button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
166
- button.setTitle("Break the world", for: [])
167
- button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
168
- view.addSubview(button)
225
+ const getVerifySnippet = ( params : Params ) =>
226
+ isManualSwift ( params )
227
+ ? `
228
+ enum MyCustomError: Error {
229
+ case myFirstIssue
230
+ }
231
+
232
+ func thisFunctionThrows() throws {
233
+ throw MyCustomError.myFirstIssue
234
+ }
169
235
170
- @IBAction func breakTheWorld(_ sender: AnyObject) {
171
- fatalError("Break the world")
236
+ func verifySentrySDK() {
237
+ do {
238
+ try thisFunctionThrows()
239
+ } catch {
240
+ SentrySDK.capture(error: error)
241
+ }
242
+ }`
243
+ : `
244
+ - (void)thisFunctionReturnsAnError:(NSError **)error {
245
+ *error = [NSError errorWithDomain:@"com.example.myapp"
246
+ code:1001
247
+ userInfo:@{
248
+ NSLocalizedDescriptionKey: @"Something went wrong."
249
+ }];
250
+ }
251
+
252
+ - (void)verifySentrySDK {
253
+ NSError *error = nil;
254
+ [self thisFunctionReturnsAnError:&error];
255
+ [SentrySDK captureError:error];
172
256
}` ;
173
257
174
258
const getReplaySetupSnippet = ( params : Params ) => `
@@ -314,28 +398,35 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
314
398
) }
315
399
</ p >
316
400
) ,
317
- configurations : [
318
- {
319
- language : 'swift' ,
320
- code : getConfigurationSnippet ( params ) ,
321
- } ,
322
- {
323
- description : (
324
- < p >
325
- { tct (
326
- "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:" ,
327
- {
328
- initializer : (
329
- < ExternalLink href = "https://developer.apple.com/documentation/swiftui/app/main()" />
330
- ) ,
331
- }
332
- ) }
333
- </ p >
334
- ) ,
335
- language : 'swift' ,
336
- code : getConfigurationSnippetSwiftUi ( params ) ,
337
- } ,
338
- ] ,
401
+ configurations : isManualSwift ( params )
402
+ ? [
403
+ {
404
+ language : 'swift' ,
405
+ code : getConfigurationSnippetSwift ( params ) ,
406
+ } ,
407
+ {
408
+ description : (
409
+ < p >
410
+ { tct (
411
+ "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:" ,
412
+ {
413
+ initializer : (
414
+ < ExternalLink href = "https://developer.apple.com/documentation/swiftui/app/main()" />
415
+ ) ,
416
+ }
417
+ ) }
418
+ </ p >
419
+ ) ,
420
+ language : 'swift' ,
421
+ code : getConfigurationSnippetSwiftUi ( params ) ,
422
+ } ,
423
+ ]
424
+ : [
425
+ {
426
+ language : 'objc' ,
427
+ code : getConfigurationSnippetObjectiveC ( params ) ,
428
+ } ,
429
+ ] ,
339
430
} ,
340
431
] ,
341
432
verify : params =>
@@ -354,17 +445,17 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
354
445
description : (
355
446
< p >
356
447
{ tct (
357
- 'This snippet contains an intentional error you can use to test that errors are uploaded to Sentry correctly. You can add it to your main [viewController: ViewController] .' ,
448
+ 'This snippet contains an intentional error you can use to test that errors are uploaded to Sentry correctly. You can call [verifySentrySDK: verifySentrySDK()] from where you want to test it .' ,
358
449
{
359
- viewController : < code /> ,
450
+ verifySentrySDK : < code /> ,
360
451
}
361
452
) }
362
453
</ p >
363
454
) ,
364
455
configurations : [
365
456
{
366
- language : 'swift' ,
367
- code : getVerifySnippet ( ) ,
457
+ language : selectedLanguage ( params ) ,
458
+ code : getVerifySnippet ( params ) ,
368
459
} ,
369
460
] ,
370
461
} ,
0 commit comments