123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>The SDK can be installed using <a class=\"reference external\" href=\"http://cocoapods.org\">CocoaPods</a> or <a class=\"reference external\" href=\"https://github.com/Carthage/Carthage\">Carthage</a>.\nThis is the recommended client for both Swift and Objective-C.</p>\n<p>We recommend installing Sentry with CocoaPods.</p>\n<p>To integrate Sentry into your Xcode project using CocoaPods, specify\nit in your <cite>Podfile</cite>:</p>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">source</span> <span style=\"color: #e8535a\">'https://github.com/CocoaPods/Specs.git'</span>\n<span style=\"color: #111111\">platform</span> <span style=\"color: #e8535a\">:ios</span><span style=\"color: #111111\">,</span> <span style=\"color: #e8535a\">'8.0'</span>\n<span style=\"color: #111111\">use_frameworks!</span>\n\n<span style=\"color: #111111\">target</span> <span style=\"color: #e8535a\">'YourApp'</span> <span style=\"color: #2eb0f7\">do</span>\n <span style=\"color: #111111\">pod</span> <span style=\"color: #e8535a\">'Sentry'</span><span style=\"color: #111111\">,</span> <span style=\"color: #e8535a\">:git</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #e8535a\">'https://github.com/getsentry/sentry-cocoa.git'</span><span style=\"color: #111111\">,</span> <span style=\"color: #e8535a\">:tag</span> <span style=\"color: #4b4f5c\">=></span> <span style=\"color: #e8535a\">'3.9.1'</span>\n<span style=\"color: #2eb0f7\">end</span>\n</pre></div>\n</div>\n<p>If you want to use Sentry without KSCrash you can just remove it from the subspecs.\nKeep in mind that if you are not using KSCrash no events will be reported whenever you app crashes.\nAlso some function might do nothing if they are related to KSCrash.</p>\n<p>Afterwards run <code class=\"docutils literal\"><span class=\"pre\">pod</span> <span class=\"pre\">install</span></code>. In case you encounter problems with\ndependencies and you are on a newer CocoaPods you might have to run\n<code class=\"docutils literal\"><span class=\"pre\">pod</span> <span class=\"pre\">repo</span> <span class=\"pre\">update</span></code> first.</p>\n<p>To integrate Sentry into your Xcode project using Carthage, specify\nit in your <cite>Cartfile</cite>:</p>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">github</span> <span style=\"color: #e8535a\">"getsentry/sentry-cocoa"</span> <span style=\"color: #e8535a\">"3.9.1"</span>\n</pre></div>\n</div>\n<p>Run <code class=\"docutils literal\"><span class=\"pre\">carthage</span> <span class=\"pre\">update</span></code> to download the framework and drag the built\n<cite>Sentry.framework</cite> into your Xcode project.</p>\n<p>Note that for Carthage we had to bundle KSCrash into the <code class=\"docutils literal\"><span class=\"pre\">Sentry.framework</span></code> to make everything work. So you will always get KSCrash with Sentry when using Carthage.</p>\n<p>We also provide a prebuilt version for every release which can be downloaded at <a class=\"reference external\" href=\"https://github.com/getsentry/sentry-cocoa/releases\">releases on github</a>.</p>\n</div>\n\n\n<div class=\"section\" id=\"configuration\">\n<h2>Configuration</h2>\n<p>To use the client, change your AppDelegate’s <cite>application</cite> method to\ninstantiate the Sentry client:</p>\n<div class=\"highlight-swift\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">Sentry</span>\n\n<span style=\"color: #2eb0f7\">func</span> <span style=\"color: #111111\">application(application:</span> <span style=\"color: #45c2c9\">UIApplication</span><span style=\"color: #111111\">,</span>\n <span style=\"color: #111111\">didFinishLaunchingWithOptions</span> <span style=\"color: #111111\">launchOptions:</span> <span style=\"color: #111111\">[</span><span style=\"color: #45c2c9\">NSObject</span><span style=\"color: #111111\">:</span> <span style=\"color: #2eb0f7\">AnyObject</span><span style=\"color: #111111\">]?)</span> <span style=\"color: #111111\">-></span> <span style=\"color: #2eb0f7\">Bool</span> <span style=\"color: #111111\">{</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Create a Sentry client and start crash handler</span>\n <span style=\"color: #2eb0f7\">do</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">Client.shared</span> <span style=\"color: #111111\">=</span> <span style=\"color: #2eb0f7\">try</span> <span style=\"color: #111111\">Client(dsn:</span> <span style=\"color: #e8535a\">"___DSN___"</span><span style=\"color: #111111\">)</span>\n <span style=\"color: #2eb0f7\">try</span> <span style=\"color: #111111\">Client.shared?.startCrashHandler()</span>\n <span style=\"color: #111111\">}</span> <span style=\"color: #2eb0f7\">catch</span> <span style=\"color: #2eb0f7\">let</span> <span style=\"color: #111111\">error</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #45c2c9\">print</span><span style=\"color: #111111\">(</span><span style=\"color: #e8535a\">"\\(</span><span style=\"color: #111111\">error</span><span style=\"color: #e8535a\">)"</span><span style=\"color: #111111\">)</span>\n <span style=\"color: #34c08b; font-style: italic\">// Wrong DSN or KSCrash not installed</span>\n <span style=\"color: #111111\">}</span>\n\n <span style=\"color: #2eb0f7\">return</span> <span style=\"color: #2eb0f7\">true</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>If you prefer to use Objective-C you can do so like this:</p>\n<div class=\"highlight-objc\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">@import</span> <span style=\"color: #111111\">Sentry;</span>\n\n<span style=\"color: #45c2c9\">NSError</span> <span style=\"color: #4b4f5c\">*</span><span style=\"color: #111111\">error</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">nil</span><span style=\"color: #111111\">;</span>\n<span style=\"color: #111111\">SentryClient</span> <span style=\"color: #4b4f5c\">*</span><span style=\"color: #111111\">client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">[[SentryClient</span> <span style=\"color: #111111\">alloc]</span> <span style=\"color: #fb4226\">initWithDsn</span><span style=\"color: #111111\">:</span><span style=\"color: #e8535a\">@"___DSN___"</span> <span style=\"color: #fb4226\">didFailWithError</span><span style=\"color: #111111\">:</span><span style=\"color: #4b4f5c\">&</span><span style=\"color: #111111\">error];</span>\n<span style=\"color: #111111\">SentryClient.sharedClient</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">client;</span>\n<span style=\"color: #111111\">[SentryClient.sharedClient</span> <span style=\"color: #fb4226\">startCrashHandlerWithError</span><span style=\"color: #111111\">:</span><span style=\"color: #4b4f5c\">&</span><span style=\"color: #111111\">error];</span>\n<span style=\"color: #2eb0f7\">if</span> <span style=\"color: #111111\">(</span><span style=\"color: #2eb0f7\">nil</span> <span style=\"color: #4b4f5c\">!=</span> <span style=\"color: #111111\">error)</span> <span style=\"color: #111111\">{</span>\n <span style=\"color: #111111\">NSLog(</span><span style=\"color: #e8535a\">@"%@"</span><span style=\"color: #111111\">,</span> <span style=\"color: #111111\">error);</span>\n<span style=\"color: #111111\">}</span>\n</pre></div>\n</div>\n<p>Note that if you call <code class=\"docutils literal\"><span class=\"pre\">startCrashHandler</span></code> will only catch errors if KSCrash is present.</p>\n</div>\n\n\n<div class=\"section\" id=\"debug-symbols\">\n<span id=\"sentry-cocoa-debug-symbols\"></span><h2>Debug Symbols</h2>\n<p>Before you can start capturing crashes you will need to tell Sentry about the debug\ninformation by uploading dSYM files. Depending on your setup this can be\ndone in different ways:</p>\n<ul class=\"simple\">\n<li><a class=\"reference internal\" href=\"https://docs.getsentry.com/clients/cocoa/dsym/#dsym-with-bitcode\"><span>With Bitcode</span></a></li>\n<li><a class=\"reference internal\" href=\"https://docs.getsentry.com/clients/cocoa/dsym/#dsym-without-bitcode\"><span>Without Bitcode</span></a></li>\n</ul>\n</div>\n\n\n<div class=\"section\" id=\"upload-symbols-with-sentry-cli\">\n<h2>Upload Symbols with <cite>sentry-cli</cite></h2>\n<p>Your project’s dSYM can be upload during the build phase as a “Run\nScript”. For this you need to st the <cite>DEBUG_INFORMATION_FORMAT</cite> to be\n<cite>DWARF with dSYM File</cite>. By default, an Xcode project will only have\n<cite>DEBUG_INFORMATION_FORMAT</cite> set to <cite>DWARF with dSYM File</cite> in <cite>Release</cite> so\nmake sure everything is set in your build settings properly.</p>\n<p>You need to have an Auth Token for this to work. You can <a class=\"reference external\" href=\"https://sentry.io/api/\">create an\nAuth Token here</a>.</p>\n<ol class=\"arabic simple\">\n<li>You will need to copy the below into a new <cite>Run Script</cite> and set your\n<cite>AUTH_TOKEN</cite>, <cite>ORG_SLUG</cite>, and <cite>PROJECT_SLUG</cite></li>\n<li>Download and install <a class=\"reference external\" href=\"https://github.com/getsentry/sentry-cli/releases\">sentry-cli</a>\n\u2014 The best place to put this is in the <cite>/usr/local/bin/</cite> directory</li>\n</ol>\n<p>Shell: <cite>/bin/bash</cite></p>\n<div class=\"highlight-bash\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">if</span> which sentry-cli >/dev/null<span style=\"color: #111111\">;</span> <span style=\"color: #2eb0f7\">then</span>\n<span style=\"color: #2eb0f7\">export</span> <span style=\"color: #111111\">SENTRY_ORG</span><span style=\"color: #4b4f5c\">=</span>___ORG_NAME___\n<span style=\"color: #2eb0f7\">export</span> <span style=\"color: #111111\">SENTRY_PROJECT</span><span style=\"color: #4b4f5c\">=</span>___PROJECT_NAME___\n<span style=\"color: #2eb0f7\">export</span> <span style=\"color: #111111\">SENTRY_AUTH_TOKEN</span><span style=\"color: #4b4f5c\">=</span>YOUR_AUTH_TOKEN\n<span style=\"color: #111111\">ERROR</span><span style=\"color: #4b4f5c\">=</span><span style=\"color: #2eb0f7\">$(</span>sentry-cli upload-dsym <span style=\"color: #45c2c9\">2</span>><span style=\"color: #111111\">&</span><span style=\"color: #45c2c9\">1</span> >/dev/null<span style=\"color: #2eb0f7\">)</span>\n<span style=\"color: #2eb0f7\">if</span> <span style=\"color: #4b4f5c\">[</span> ! <span style=\"color: #111111\">$?</span> -eq <span style=\"color: #45c2c9\">0</span> <span style=\"color: #4b4f5c\">]</span><span style=\"color: #111111\">;</span> <span style=\"color: #2eb0f7\">then</span>\n<span style=\"color: #2eb0f7\">echo</span> <span style=\"color: #e8535a\">"warning: sentry-cli - </span><span style=\"color: #111111\">$ERROR</span><span style=\"color: #e8535a\">"</span>\n<span style=\"color: #2eb0f7\">fi</span>\n<span style=\"color: #2eb0f7\">else</span>\n<span style=\"color: #2eb0f7\">echo</span> <span style=\"color: #e8535a\">"warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases"</span>\n<span style=\"color: #2eb0f7\">fi</span>\n</pre></div>\n</div>\n<p>The <code class=\"docutils literal\"><span class=\"pre\">upload-dsym</span></code> command automatically picks up the\n<code class=\"docutils literal\"><span class=\"pre\">DWARF_DSYM_FOLDER_PATH</span></code> environment variable that Xcode exports and\nlook for dSYM files there.</p>\n<div class=\"admonition-on-prem admonition\">\n<p class=\"first admonition-title\">On Prem</p>\n<p>By default sentry-cli will connect to sentry.io. For\non-prem you need to export the <cite>SENTRY_URL</cite> environment variable\nto instruct the tool to connect to your server:</p>\n<div class=\"last highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>export SENTRY_URL=https://mysentry.invalid/\n</pre></div>\n</div>\n</div>\n</div>\n",
- "link": "https://docs.getsentry.com/platforms/ios/",
- "id": "apple-ios",
- "name": "iOS"
- }
|