@@ -20,7 +20,8 @@ import {getWizardInstallSnippet} from 'sentry/utils/gettingStartedDocs/mobileWiz
2020
2121export enum InstallationMode {
2222 AUTO = 'auto' ,
23- MANUAL = 'manual' ,
23+ MANUAL_SWIFT = 'manual-swift' ,
24+ MANUAL_OBJECTIVE_C = 'manual-objective-c' ,
2425}
2526
2627const platformOptions = {
@@ -32,8 +33,12 @@ const platformOptions = {
3233 value : InstallationMode . AUTO ,
3334 } ,
3435 {
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 ,
3742 } ,
3843 ] ,
3944 defaultValue : InstallationMode . AUTO ,
@@ -46,14 +51,19 @@ type Params = DocsParams<PlatformOptions>;
4651const isAutoInstall = ( params : Params ) =>
4752 params . platformOptions . installationMode === InstallationMode . AUTO ;
4853
54+ const isManualSwift = ( params : Params ) =>
55+ params . platformOptions . installationMode === InstallationMode . MANUAL_SWIFT ;
56+
57+ const selectedLanguage = ( params : Params ) => ( isManualSwift ( params ) ? 'swift' : 'objc' ) ;
58+
4959const getManualInstallSnippet = ( params : Params ) => `
5060.package(url: "https://github.com/getsentry/sentry-cocoa", from: "${ getPackageVersion (
5161 params ,
5262 'sentry.cocoa' ,
5363 '8.49.0'
5464) } "),`;
5565
56- const getConfigurationSnippet = ( params : Params ) => `
66+ const getConfigurationSnippetSwift = ( params : Params ) => `
5767import Sentry
5868
5969// ....
@@ -108,6 +118,58 @@ func application(_ application: UIApplication,
108118 return true
109119}` ;
110120
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+
111173const getConfigurationSnippetSwiftUi = ( params : Params ) => `
112174import Sentry
113175
@@ -160,15 +222,37 @@ struct SwiftUIApp: App {
160222 }
161223}` ;
162224
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+ }
169235
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];
172256}` ;
173257
174258const getReplaySetupSnippet = ( params : Params ) => `
@@ -314,28 +398,35 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
314398 ) }
315399 </ p >
316400 ) ,
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+ ] ,
339430 } ,
340431 ] ,
341432 verify : params =>
@@ -354,17 +445,17 @@ const onboarding: OnboardingConfig<PlatformOptions> = {
354445 description : (
355446 < p >
356447 { 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 .' ,
358449 {
359- viewController : < code /> ,
450+ verifySentrySDK : < code /> ,
360451 }
361452 ) }
362453 </ p >
363454 ) ,
364455 configurations : [
365456 {
366- language : 'swift' ,
367- code : getVerifySnippet ( ) ,
457+ language : selectedLanguage ( params ) ,
458+ code : getVerifySnippet ( params ) ,
368459 } ,
369460 ] ,
370461 } ,
0 commit comments