CINXE.COM

iOS SDK | Bitly Developer

<!DOCTYPE html><html lang="en"><head><script type="text/javascript" src="https://web-static.archive.org/_static/js/bundle-playback.js?v=7YQSqjSh" charset="utf-8"></script> <script type="text/javascript" src="https://web-static.archive.org/_static/js/wombat.js?v=txqj7nKC" charset="utf-8"></script> <script>window.RufflePlayer=window.RufflePlayer||{};window.RufflePlayer.config={"autoplay":"on","unmuteOverlay":"hidden"};</script> <script type="text/javascript" src="https://web-static.archive.org/_static/js/ruffle/ruffle.js"></script> <script type="text/javascript"> __wm.init("https://web.archive.org/web"); __wm.wombat("https://dev.bitly.com/docs/sdks/ios-sdk","20220911161327","https://web.archive.org/","web","https://web-static.archive.org/_static/", "1662912807"); </script> <link rel="stylesheet" type="text/css" href="https://web-static.archive.org/_static/css/banner-styles.css?v=p7PEIJWi" /> <link rel="stylesheet" type="text/css" href="https://web-static.archive.org/_static/css/iconochive.css?v=3PDvdIFv" /> <!-- End Wayback Rewrite JS Include --> <meta name="viewport" content="width=device-width"/><meta charset="utf-8"/><link rel="shortcut icon" href="https://web.archive.org/web/20220911161327im_/https://dl6fh5ptkejqa.cloudfront.net/0482a3c938673192a591f2845b9eb275.png" type="image/x-icon"/><title>iOS SDK | Bitly Developer</title><meta name="next-head-count" content="4"/><link rel="preload" href="/web/20220911161327/https://dev.bitly.com/_next/static/css/864e502d90faa99e.css" as="style"/><link rel="stylesheet" href="/web/20220911161327cs_/https://dev.bitly.com/_next/static/css/864e502d90faa99e.css" data-n-g=""/><link rel="preload" href="/web/20220911161327/https://dev.bitly.com/_next/static/css/1927f8520746651a.css" as="style"/><link rel="stylesheet" href="/web/20220911161327cs_/https://dev.bitly.com/_next/static/css/1927f8520746651a.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/polyfills-5cd94c89d3acac5f.js"></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/webpack-9b312e20a4e32339.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/framework-980c61186da74c3e.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/main-f834e365d114b764.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/pages/_app-a70a1b36c9f950d3.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/31-c2af656762807683.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/988-49cc8d1b9808d55e.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/659-31d1cb5412d53ead.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/chunks/pages/docs/%5B...docs%5D-0c25665bad649a81.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/63fcc1ddce08a26dd351c07b982972011d09e8a1/_buildManifest.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/63fcc1ddce08a26dd351c07b982972011d09e8a1/_ssgManifest.js" defer=""></script><script src="/web/20220911161327js_/https://dev.bitly.com/_next/static/63fcc1ddce08a26dd351c07b982972011d09e8a1/_middlewareManifest.js" defer=""></script></head><body><div id="__next" data-reactroot=""><div class="Layout_layout__WuuTt"><div class="Layout_header__HIFcZ"><header class="Header_header__jiqMu"><div class="Header_headerContent__6viXb"><div class="Header_headerIcon__fYgGU"><svg xmlns="http://www.w3.org/2000/svg" viewbox="-1376 546.6 90 45" xml:space="preserve"><title>Bitly</title><path d="M-1329.1 577c-4.5 0-7-2.7-7-6 0-1.3.1-11.4.1-11.4-1.5 0-2.2-.8-2.2-1.7 0-1 .8-1.9 2-1.9v-4.7c0-1.6 1.2-2.9 2.8-2.9 1.6 0 2.8 1.3 2.8 2.9 0 1.2-.1 2.8-.1 4.7h2.9c1.5 0 2.2.8 2.2 1.9 0 1.1-.8 1.8-1.9 1.8h-3.2c-.1 3.2-.2 7.1-.2 10.1 0 1.1.8 2.4 2.6 2.4 4.3 0 5.5-4.3 5.5-12.4 0-1.1.9-1.9 1.9-1.9 1.1 0 1.9.8 1.9 1.9.1 10.7-2.5 17.2-10.1 17.2"></path><path d="M-1310.9 560.5s1.8-1.2 2.9-1.2c1.1 0 .9.2.9 1.3 0 11.6-2.1 16.5-9.6 16.5-3.3 0-6.3-2.4-6.3-5.4 0-1.2.2-3.5.2-4.6 0-11.2-.2-13.5-.2-16.8 0-1.6 1.3-3 2.9-3 1.6 0 2.8 1.3 2.8 2.9 0 3.3-.4 8-.5 20.4 0 1 .5 1.8 1.8 1.8 4.3-.2 4.9-5.1 5.1-11.9"></path><path d="M-1297.3 575s-1.6 2.1-5.6 2c-5.3-.1-7.7-4.3-8-8.6-.2-3.3-.1-5.1-.1-7.3 0-1.6 1.1-2.9 2.6-2.9 1.6 0 2.5 1.3 2.5 2.9 0 2.1-.1 3.5-.2 5.9 0 2.8.9 5.3 3.2 5.2 2.2 0 4.7-.9 4.7-5.7v-5.4c0-1.6 1.1-2.9 2.7-2.9s2.7 1.3 2.7 2.9c0 2.1-.2 3.8-.2 7.1 0 0-.1 6.6.1 8.1.7-.2 1.8-1 2.9-2.7.7-1 2-1.3 2.7-.8 1.1.6 1.1 1.9.6 2.8-1.1 2.3-2.4 3.8-5.9 5 0 4-.3 9.8-7.6 10.9-6.3.9-9.1-2.7-9.1-5.8 0-4.9 4.9-6.3 11.9-8.1l.1-2.6zm.6 6.4c-3.6.8-8 1.9-8 4.1 0 2.1 2.2 2.4 4 2.1 3.7-.8 4.1-3 4-6.2zM-1347.6 571.6c0-1.3-.2-12.2-.2-12.2 0-1.6 1-2.9 2.6-2.9s2.6 1.4 2.6 2.9c-.2 5.1-.3 8.4-.3 10.2 0 1 .6 2.6 2.2 2.6 3.8 0 4.6-3.5 4.6-12.1 0-1.1 1.1-1.9 2.2-1.9s1.9.8 1.9 1.9c0 13-2.3 16.9-9.6 16.9-2.8 0-6-1.9-6-5.4"></path><path d="M-1345.8 557.5c-1.1 0-1.1.2-1.8 1.3 0 4.8-1.2 10.7-6.6 12.9 3.8-8-.1-15.3-6.4-15.3-3 0-4.9 1.1-6.1 2.1 0-2.3.1-6.4.1-6.4 0-2.9-1-5.1-4.5-5.2-2 0-3.5.9-4.5 3-.3.8-.2 1.6.5 2 .6.3 1.5.1 1.9-.5.3-.4.5-.5.7-.4.4 0 .4.7.5 1.2 0 .3.3 5.1.2 17.7 0 3.5 2.7 7.5 9.3 7.5 13 0 18.6-4.8 18.6-17.7-.3-1.2-.9-2.2-1.9-2.2zm-16.9 14.9c-2.5 0-4.2-.7-4.3-2.9v-2.2c.2-3.1 2.4-5.4 4.6-5.8 2.7-.5 4.5.7 4.5 4.2-.1 2.4-.8 6.6-4.8 6.7zM-1345.1 548.4c1.6 0 2.9 1.3 2.9 2.9s-1.3 2.9-2.9 2.9c-1.6 0-2.9-1.3-2.9-2.9s1.3-2.9 2.9-2.9"></path></svg>Developer</div><div class="Header_desktopHeaderLinks__afkP5"><nav><a class="Header_link__GeEkF Header_activeLink__QO_Eu" href="/web/20220911161327/https://dev.bitly.com/">Documentation</a><a class="Header_link__GeEkF" href="/web/20220911161327/https://dev.bitly.com/api-reference/">API Reference</a></nav><div class="Header_ctaWrapper__rejBO"><a class="Button_button__45M_W" href="https://web.archive.org/web/20220911161327/https://bitly.com/pages/pricing" target="_blank" rel="noopener noreferrer">Start Now</a></div></div><div class="Header_mobileHamburger__i_8mq"><div class="Header_menuIcon__5w7RR"><svg height="32" style="enable-background:new 0 0 32 32" width="32" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><title>Navigation</title><path d="M4 10h24a2 2 0 0 0 0-4H4a2 2 0 0 0 0 4zm24 4H4a2 2 0 0 0 0 4h24a2 2 0 0 0 0-4zm0 8H4a2 2 0 0 0 0 4h24a2 2 0 0 0 0-4z"></path></svg></div></div></div></header></div><div class="Layout_body__KWn_X"><nav class="Layout_navigation__1M5jp Layout_navigationHide__DviHj"><div class="Header_mobileHeaderLinks__EmNZ6"><nav><a class="Header_link__GeEkF Header_activeLink__QO_Eu" href="/web/20220911161327/https://dev.bitly.com/">Documentation</a><a class="Header_link__GeEkF" href="/web/20220911161327/https://dev.bitly.com/api-reference/">API Reference</a></nav><div class="Header_ctaWrapper__rejBO"><a class="Button_button__45M_W" href="https://web.archive.org/web/20220911161327/https://bitly.com/pages/pricing" target="_blank" rel="noopener noreferrer">Start Now</a></div></div><div><div class="SideNavHeader_sideNavHeader__sGWeT">Getting Started</div><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/getting-started/introduction/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Introduction</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/getting-started/authentication/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Authentication</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/getting-started/rate-limits/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Rate Limits</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/getting-started/troubleshooting-tips/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Troubleshooting &amp; Tips</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/getting-started/migrating-from-v3/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Migrating from V3</div></div></a><div class="SideNavHeader_sideNavHeader__sGWeT">Tutorials</div><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/tutorials/create-a-test-account/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Create a Test Account</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/tutorials/shorten-customize-links/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Shorten &amp; Customize Links</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/tutorials/retrieve-metrics/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Retrieve Metrics</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/tutorials/create-a-webhook/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Create a Webhook</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/tutorials/integrate-bitly-in-your-app/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Integrate Bitly in Your App</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/tutorials/generate-qr-codes/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Generate QR Codes</div></div></a><div class="SideNavHeader_sideNavHeader__sGWeT">SDKs</div><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/sdks/openapi-30/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">OpenAPI 3.0</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/sdks/android-sdk/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST">Android SDK</div></div></a><a class="SideNavLink_anchor__sjeOh" href="/web/20220911161327/https://dev.bitly.com/docs/sdks/ios-sdk/"><div class="SideNavLink_sideNavLink__gSTmq"><div class="SideNavLink_content__aDTST SideNavLink_selected__khrV0">iOS SDK</div></div></a></div></nav><main class="Layout_content__Dwd3J"><div class="Markdown_Markdown__68s8u"><h1>Bitly iOS SDK</h1> <h2>Configure your iOS app</h2> <p>Before integrating the SDK you will need to configure your iOS app in Bitly. To do this, sign in to Bitly, open the profile menu, select <strong>Settings</strong>, click <strong>Mobile deep links</strong> below your account name, and click <strong>Add a mobile application</strong>.</p> <p>When creating the iOS app you will need to provide your Apple ID. The Apple ID is your Apple Team ID and bundle ID joined with a period (for example, 1A234H7ABC.com.yourdomain.YourApp). To get your Team ID, log in to <a href="https://web.archive.org/web/20220911161327/http://developer.apple.com/" rel="noreferrer" target="_blank">Apple鈥檚 Developer Portal</a> and click <strong>Membership</strong> in the navigation menu. Your Team ID is displayed under Membership Details. If you choose to implement a Custom Scheme, you can also enter that during the app creation process.</p> <p>Once the app is created, an app ID will be available on Bitly&#x27;s app detail panel. Copy the ID for later in the setup.</p> <p>To associate your app to your custom link domain in Bitly, you&#x27;ll need to create an Apple Site Association File. To create the file, go to the profile menu, select <strong>Settings</strong>, and click <strong>Custom domains</strong> below your account name. Select your domain, click <strong>Configure</strong> in the Mobile behavior section, and then select the newly created iOS app. After saving the changes you can validate the file exists by going to https://<!-- -->&lt;i&gt;<!-- -->&lt;/i&gt;<!-- -->yourdomain.com/.well-known/apple-app-site-association.</p> <h2>Install the SDK</h2> <h3>CocoaPods</h3> <ol> <li> <p>Add the following to your Podfile</p> <div><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code style="white-space:pre"><span>pod &#x27;BitlySDK&#x27; </span></code></pre></div></div></div> </li> <li> <p>Run the following to download and install the SDK</p> <div><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code style="white-space:pre"><span>pod install </span></code></pre></div></div></div> </li> </ol> <h3>Carthage</h3> <ol> <li> <p>Add the following to your Cartfile</p> <div><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code style="white-space:pre"><span>github &quot;bitly/bitly_ios_sdk_release&quot; </span></code></pre></div></div></div> </li> <li> <p>Run the following to download and build the framework</p> <div><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code style="white-space:pre"><span>carthage update </span></code></pre></div></div></div> </li> <li> <p>Drag the built <code>BitlySDK.framework</code> into your Xcode project</p> </li> </ol> <h3>Configure the Universal Links</h3> <ol> <li> <p>In Xcode open your project file</p> </li> <li> <p>Go to the Capabilities tab</p> </li> <li> <p>Ensure that Associated Domains is enabled and expand it</p> </li> <li> <p>Click on the + button and add your domain as <code>applinks:yourdomain.com</code></p> </li> <li> <p>Ensure that the yourprojectname.entitlements file is added to the appropriate build target</p> </li> </ol> <h3>Configure the Custom Scheme</h3> <ol> <li> <p>In Xcode open your Info.plist</p> </li> <li> <p>Add a row for &quot;URL types&quot; as an array</p> </li> <li> <p>Add an entry to that array as &quot;URL Schemes&quot; also as an array</p> </li> <li> <p>Add a row with your custom scheme as the value</p> </li> </ol> <blockquote> <p>Custom Schemes are the older way of handling deep linking. However having an app that supports both Universal Links and Custom Schemes allows Bitly to work with Facebook App Links, Facebook Ads and other apps that launch content utilizing Custom Scheme deep links.</p> </blockquote> <h3>Configure the SDK for Deep Links</h3> <ol> <li> <p>Import the SDK in your AppDelegate</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token keyword">import</span><span> </span><span class="token token class-name">BitlySDK</span></code></pre></div></div></div> </li> <li> <p>Initialize the SDK on application initialization</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token keyword">func</span><span> </span><span class="token token function-definition" style="color:#224CB4">application</span><span class="token token punctuation">(</span><span>application</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">UIApplication</span><span class="token token punctuation">,</span><span> didFinishLaunchingWithOptions launchOptions</span><span class="token token punctuation">:</span><span> </span><span class="token token punctuation">[</span><span class="token token class-name">NSObject</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">AnyObject</span><span class="token token punctuation">]</span><span class="token token operator">?</span><span class="token token punctuation">)</span><span> </span><span class="token token operator">-&gt;</span><span> </span><span class="token token class-name">Bool</span><span> </span><span class="token token punctuation">{</span><span> </span><span> </span><span class="token token class-name">Bitly</span><span class="token token punctuation">.</span><span class="token token" style="color:#224CB4">initialize</span><span class="token token punctuation">(</span><span class="token token string-literal" style="color:#51763e">&quot;YOUR_APP_ID&quot;</span><span class="token token punctuation">,</span><span> supportedDomains</span><span class="token token punctuation">:</span><span class="token token punctuation">[</span><span class="token token string-literal" style="color:#51763e">&quot;yourdomain.com&quot;</span><span class="token token punctuation">,</span><span class="token token string-literal" style="color:#51763e">&quot;yourotherdomain.com&quot;</span><span class="token token punctuation">]</span><span class="token token punctuation">,</span><span> supportedSchemes</span><span class="token token punctuation">:</span><span class="token token punctuation">[</span><span class="token token string-literal" style="color:#51763e">&quot;yourscheme&quot;</span><span class="token token punctuation">]</span><span class="token token punctuation">)</span><span> </span><span class="token token punctuation">{</span><span> response</span><span class="token token punctuation">,</span><span> error </span><span class="token token keyword">in</span><span> </span><span> </span><span class="token token comment">// response provides a BitlyResponse object which contains the full URL information</span><span> </span><span> </span><span class="token token comment">// response includes a status code</span><span> </span><span> </span><span class="token token comment">// error provides any errors in retrieving information about the URL</span><span> </span><span> </span><span class="token token comment">// Your custom logic goes here...</span><span> </span><span> </span><span class="token token punctuation">}</span><span> </span><span> </span><span class="token token keyword">return</span><span> </span><span class="token token" style="color:#94340A">true</span><span> </span><span></span><span class="token token punctuation">}</span></code></pre></div></div></div> <blockquote> <p>By default the Bitly SDK utilizes the IDFV to identify the user. If you which to use the IDFA to track the user simply provide the <code>deviceId</code> to the appropriate method when initializing the SDK. You can also provide the access token for shortening with the <code>accessToken</code> provided to the initializing methods.</p> </blockquote> </li> <li> <p>Handle incoming links</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token keyword">func</span><span> </span><span class="token token function-definition" style="color:#224CB4">application</span><span class="token token punctuation">(</span><span class="token token omit keyword">_</span><span> application</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">UIApplication</span><span class="token token punctuation">,</span><span> </span><span class="token token keyword">continue</span><span class="token token label important"> userActivity</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">NSUserActivity</span><span class="token token punctuation">,</span><span> restorationHandler</span><span class="token token punctuation">:</span><span> </span><span class="token token attribute atrule">@escaping</span><span> </span><span class="token token punctuation">(</span><span class="token token punctuation">[</span><span class="token token keyword">Any</span><span class="token token punctuation">]</span><span class="token token operator">?</span><span class="token token punctuation">)</span><span> </span><span class="token token operator">-&gt;</span><span> </span><span class="token token class-name">Void</span><span class="token token punctuation">)</span><span> </span><span class="token token operator">-&gt;</span><span> </span><span class="token token class-name">Bool</span><span> </span><span class="token token punctuation">{</span><span> </span><span> </span><span class="token token keyword">return</span><span> </span><span class="token token class-name">Bitly</span><span class="token token punctuation">.</span><span class="token token" style="color:#224CB4">handle</span><span class="token token punctuation">(</span><span>userActivity</span><span class="token token punctuation">)</span><span> </span><span></span><span class="token token punctuation">}</span><span> </span> <span></span><span class="token token keyword">func</span><span> </span><span class="token token function-definition" style="color:#224CB4">application</span><span class="token token punctuation">(</span><span class="token token omit keyword">_</span><span> app</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">UIApplication</span><span class="token token punctuation">,</span><span> </span><span class="token token keyword">open</span><span> url</span><span class="token token punctuation">:</span><span> </span><span class="token token constant">URL</span><span class="token token punctuation">,</span><span> options</span><span class="token token punctuation">:</span><span> </span><span class="token token punctuation">[</span><span class="token token class-name">UIApplicationOpenURLOptionsKey</span><span> </span><span class="token token punctuation">:</span><span> </span><span class="token token keyword">Any</span><span class="token token punctuation">]</span><span> </span><span class="token token operator">=</span><span> </span><span class="token token punctuation">[</span><span class="token token punctuation">:</span><span class="token token punctuation">]</span><span class="token token punctuation">)</span><span> </span><span class="token token operator">-&gt;</span><span> </span><span class="token token class-name">Bool</span><span> </span><span class="token token punctuation">{</span><span> </span><span> </span><span class="token token keyword">return</span><span> </span><span class="token token class-name">Bitly</span><span class="token token punctuation">.</span><span class="token token" style="color:#224CB4">handleOpen</span><span class="token token punctuation">(</span><span>url</span><span class="token token punctuation">)</span><span> </span><span></span><span class="token token punctuation">}</span></code></pre></div></div></div> </li> <li> <p>Retry on error</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token class-name">Bitly</span><span class="token token punctuation">.</span><span class="token token" style="color:#224CB4">retryError</span><span class="token token punctuation">(</span><span>error</span><span class="token token punctuation">)</span></code></pre></div></div></div> <blockquote> <p>If there are any issues in handling a Universal Link the operation can be retried using the following line of code in your response handler from step 2</p> </blockquote> </li> </ol> <h2>Configure the SDK for Shortening</h2> <ol> <li> <p>Configure an OAuth token for your app in your Bitly <a href="https://web.archive.org/web/20220911161327/https://app.bitly.com/settings/api/" rel="noreferrer" target="_blank">settings</a>.</p> </li> <li> <p>Import the SDK in your AppDelegate</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token keyword">import</span><span> </span><span class="token token class-name">BitlySDK</span></code></pre></div></div></div> </li> <li> <p>Initialize the SDK on application initialization</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token keyword">func</span><span> </span><span class="token token function-definition" style="color:#224CB4">application</span><span class="token token punctuation">(</span><span>application</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">UIApplication</span><span class="token token punctuation">,</span><span> didFinishLaunchingWithOptions launchOptions</span><span class="token token punctuation">:</span><span> </span><span class="token token punctuation">[</span><span class="token token class-name">NSObject</span><span class="token token punctuation">:</span><span> </span><span class="token token class-name">AnyObject</span><span class="token token punctuation">]</span><span class="token token operator">?</span><span class="token token punctuation">)</span><span> </span><span class="token token operator">-&gt;</span><span> </span><span class="token token class-name">Bool</span><span> </span><span class="token token punctuation">{</span><span> </span><span> </span><span class="token token class-name">Bitly</span><span class="token token punctuation">.</span><span class="token token" style="color:#224CB4">initialize</span><span class="token token punctuation">(</span><span class="token token string-literal" style="color:#51763e">&quot;YOUR_APP_ACCESS_TOKEN&quot;</span><span class="token token punctuation">)</span><span> </span><span> </span><span class="token token keyword">return</span><span> </span><span class="token token" style="color:#94340A">true</span><span> </span><span></span><span class="token token punctuation">}</span></code></pre></div></div></div> <blockquote> <p>You can combine this initialization with the App Link initialization</p> </blockquote> </li> <li> <p>You can shorten from anywhere in your application</p> <div><label class="CodeSyntaxSelector_header__6P_Jc"><span></span><div class="Select_wrapper__58utF"><select class="Select_select__qXz_Z" aria-label="Select" autocomplete="off"><option selected="" value="swift">swift</option><option value="objectivec">objectivec</option></select><svg viewbox="0 0 8 14" xmlns="http://www.w3.org/2000/svg"><path d="M6.463 7 .987 1.66a.61.61 0 0 1 0-.878.648.648 0 0 1 .9 0L7.813 6.56a.61.61 0 0 1 0 .878l-5.926 5.78a.648.648 0 0 1-.9 0 .61.61 0 0 1 0-.879L6.463 7Z"></path></svg></div></label><div class="CodeSyntaxSelector_body__hBJ7j" tabindex="0"><div class="CodeBlock_codeBlock__KlURa"><pre tabindex="0" style="color:#36383b;font-family:ProximaNova, monospace;line-height:1.2;font-size:1rem"><code class="language-swift" style="white-space:pre"><span class="token token class-name">Bitly</span><span class="token token punctuation">.</span><span class="token token" style="color:#224CB4">shorten</span><span class="token token punctuation">(</span><span class="token token string-literal" style="color:#51763e">&quot;http://theurlyouwishtoshorten.com&quot;</span><span class="token token punctuation">)</span><span> </span><span class="token token punctuation">{</span><span> response</span><span class="token token punctuation">,</span><span> error </span><span class="token token keyword">in</span><span> </span><span> </span><span class="token token comment">// response provides a BitlyResponse object which contains the shortened Bitlink</span><span> </span><span> </span><span class="token token comment">// response includes a status code</span><span> </span><span> </span><span class="token token comment">// error provides any errors in retrieving information about the URL</span><span> </span><span> </span><span class="token token comment">// Your custom logic goes here...</span><span> </span><span></span><span class="token token punctuation">}</span></code></pre></div></div></div> </li> </ol></div><footer><div class="Footer_footer__7PvU2"><div class="Footer_row__1ruA0"><div class="Footer_title__Ct_v_">Resources</div><a target="_blank" rel="noopener noreferrer" href="https://web.archive.org/web/20220911161327/https://bitly.com/blog/" class="Footer_link__V8hyW">Blog</a><a target="_blank" rel="noopener noreferrer" href="https://web.archive.org/web/20220911161327/https://bitly.com/pages/resources/" class="Footer_link__V8hyW">Webinar and Ebooks</a></div><div class="Footer_row__1ruA0"><div class="Footer_title__Ct_v_">Legal</div><a target="_blank" rel="noopener noreferrer" href="https://web.archive.org/web/20220911161327/https://bitly.com/pages/privacy/" class="Footer_link__V8hyW">Privacy Policy</a><a target="_blank" rel="noopener noreferrer" href="https://web.archive.org/web/20220911161327/https://bitly.com/pages/terms-of-service/" class="Footer_link__V8hyW">Terms of Service</a></div><div class="Footer_row__1ruA0"><div class="Footer_title__Ct_v_">Company</div><a target="_blank" rel="noopener noreferrer" href="https://web.archive.org/web/20220911161327/https://bitly.com/pages/careers/" class="Footer_link__V8hyW">Careers</a><a target="_blank" rel="noopener noreferrer" href="https://web.archive.org/web/20220911161327/mailto:api@bit.ly" class="Footer_link__V8hyW">Contact</a></div><div class="Footer_row__1ruA0"><svg xmlns="http://www.w3.org/2000/svg" viewbox="-1376 546.6 90 45" xml:space="preserve"><title>Bitly</title><path d="M-1329.1 577c-4.5 0-7-2.7-7-6 0-1.3.1-11.4.1-11.4-1.5 0-2.2-.8-2.2-1.7 0-1 .8-1.9 2-1.9v-4.7c0-1.6 1.2-2.9 2.8-2.9 1.6 0 2.8 1.3 2.8 2.9 0 1.2-.1 2.8-.1 4.7h2.9c1.5 0 2.2.8 2.2 1.9 0 1.1-.8 1.8-1.9 1.8h-3.2c-.1 3.2-.2 7.1-.2 10.1 0 1.1.8 2.4 2.6 2.4 4.3 0 5.5-4.3 5.5-12.4 0-1.1.9-1.9 1.9-1.9 1.1 0 1.9.8 1.9 1.9.1 10.7-2.5 17.2-10.1 17.2"></path><path d="M-1310.9 560.5s1.8-1.2 2.9-1.2c1.1 0 .9.2.9 1.3 0 11.6-2.1 16.5-9.6 16.5-3.3 0-6.3-2.4-6.3-5.4 0-1.2.2-3.5.2-4.6 0-11.2-.2-13.5-.2-16.8 0-1.6 1.3-3 2.9-3 1.6 0 2.8 1.3 2.8 2.9 0 3.3-.4 8-.5 20.4 0 1 .5 1.8 1.8 1.8 4.3-.2 4.9-5.1 5.1-11.9"></path><path d="M-1297.3 575s-1.6 2.1-5.6 2c-5.3-.1-7.7-4.3-8-8.6-.2-3.3-.1-5.1-.1-7.3 0-1.6 1.1-2.9 2.6-2.9 1.6 0 2.5 1.3 2.5 2.9 0 2.1-.1 3.5-.2 5.9 0 2.8.9 5.3 3.2 5.2 2.2 0 4.7-.9 4.7-5.7v-5.4c0-1.6 1.1-2.9 2.7-2.9s2.7 1.3 2.7 2.9c0 2.1-.2 3.8-.2 7.1 0 0-.1 6.6.1 8.1.7-.2 1.8-1 2.9-2.7.7-1 2-1.3 2.7-.8 1.1.6 1.1 1.9.6 2.8-1.1 2.3-2.4 3.8-5.9 5 0 4-.3 9.8-7.6 10.9-6.3.9-9.1-2.7-9.1-5.8 0-4.9 4.9-6.3 11.9-8.1l.1-2.6zm.6 6.4c-3.6.8-8 1.9-8 4.1 0 2.1 2.2 2.4 4 2.1 3.7-.8 4.1-3 4-6.2zM-1347.6 571.6c0-1.3-.2-12.2-.2-12.2 0-1.6 1-2.9 2.6-2.9s2.6 1.4 2.6 2.9c-.2 5.1-.3 8.4-.3 10.2 0 1 .6 2.6 2.2 2.6 3.8 0 4.6-3.5 4.6-12.1 0-1.1 1.1-1.9 2.2-1.9s1.9.8 1.9 1.9c0 13-2.3 16.9-9.6 16.9-2.8 0-6-1.9-6-5.4"></path><path d="M-1345.8 557.5c-1.1 0-1.1.2-1.8 1.3 0 4.8-1.2 10.7-6.6 12.9 3.8-8-.1-15.3-6.4-15.3-3 0-4.9 1.1-6.1 2.1 0-2.3.1-6.4.1-6.4 0-2.9-1-5.1-4.5-5.2-2 0-3.5.9-4.5 3-.3.8-.2 1.6.5 2 .6.3 1.5.1 1.9-.5.3-.4.5-.5.7-.4.4 0 .4.7.5 1.2 0 .3.3 5.1.2 17.7 0 3.5 2.7 7.5 9.3 7.5 13 0 18.6-4.8 18.6-17.7-.3-1.2-.9-2.2-1.9-2.2zm-16.9 14.9c-2.5 0-4.2-.7-4.3-2.9v-2.2c.2-3.1 2.4-5.4 4.6-5.8 2.7-.5 4.5.7 4.5 4.2-.1 2.4-.8 6.6-4.8 6.7zM-1345.1 548.4c1.6 0 2.9 1.3 2.9 2.9s-1.3 2.9-2.9 2.9c-1.6 0-2.9-1.3-2.9-2.9s1.3-2.9 2.9-2.9"></path></svg><div class="Footer_description__eC8la">漏 2020 Bitly</div><div class="Footer_description__eC8la">Handmade in NYC, San Francisco, Denver, and all over the world.</div><div class="Footer_socialIcons__dFxBT"><a href="https://web.archive.org/web/20220911161327/https://twitter.com/bitly" target="_blank" rel="noopener noreferrer"><svg width="24" height="20" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 2.382c-.885.399-1.83.67-2.825.794A5.063 5.063 0 0 0 23.291.384a10.01 10.01 0 0 1-3.127 1.214A4.844 4.844 0 0 0 16.574 0c-2.718 0-4.92 2.259-4.92 5.041 0 .4.045.785.127 1.153C7.69 5.996 4.066 3.982 1.64.938a5.04 5.04 0 0 0-.666 2.538 5.08 5.08 0 0 0 2.188 4.2 4.812 4.812 0 0 1-2.228-.632v.062c0 2.445 1.693 4.485 3.946 4.95a4.88 4.88 0 0 1-2.212.086c.63 2.003 2.445 3.463 4.604 3.504A9.714 9.714 0 0 1 0 17.736 13.745 13.745 0 0 0 7.557 20c9.053 0 13.998-7.685 13.998-14.34 0-.214 0-.43-.015-.645.961-.707 1.8-1.6 2.46-2.613l-.047-.02Z" fill="#121314"></path></svg></a><a href="https://web.archive.org/web/20220911161327/https://www.instagram.com/bitly/" target="_blank" rel="noopener noreferrer"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"><title>Instagram</title><path d="M12 0C8.74 0 8.333.015 7.053.072 5.775.132 4.905.333 4.14.63a5.876 5.876 0 0 0-2.126 1.384A5.855 5.855 0 0 0 .63 4.14C.333 4.905.131 5.775.072 7.053.012 8.333 0 8.74 0 12s.015 3.667.072 4.947c.06 1.277.261 2.148.558 2.913a5.885 5.885 0 0 0 1.384 2.126A5.868 5.868 0 0 0 4.14 23.37c.766.296 1.636.499 2.913.558C8.333 23.988 8.74 24 12 24s3.667-.015 4.947-.072c1.277-.06 2.148-.262 2.913-.558a5.898 5.898 0 0 0 2.126-1.384 5.86 5.86 0 0 0 1.384-2.126c.296-.765.499-1.636.558-2.913.06-1.28.072-1.687.072-4.947s-.015-3.667-.072-4.947c-.06-1.277-.262-2.149-.558-2.913a5.89 5.89 0 0 0-1.384-2.126A5.847 5.847 0 0 0 19.86.63c-.765-.297-1.636-.499-2.913-.558C15.667.012 15.26 0 12 0Zm0 2.16c3.203 0 3.585.016 4.85.071 1.17.055 1.805.249 2.227.415.562.217.96.477 1.382.896.419.42.679.819.896 1.381.164.422.36 1.057.413 2.227.057 1.266.07 1.646.07 4.85 0 3.204-.015 3.585-.074 4.85-.061 1.17-.256 1.805-.421 2.227a3.81 3.81 0 0 1-.899 1.382 3.744 3.744 0 0 1-1.38.896c-.42.164-1.065.36-2.235.413-1.274.057-1.649.07-4.859.07-3.211 0-3.586-.015-4.859-.074-1.171-.061-1.816-.256-2.236-.421a3.716 3.716 0 0 1-1.379-.899 3.644 3.644 0 0 1-.9-1.38c-.165-.42-.359-1.065-.42-2.235-.045-1.26-.061-1.649-.061-4.844 0-3.196.016-3.586.061-4.861.061-1.17.255-1.814.42-2.234.21-.57.479-.96.9-1.381.419-.419.81-.689 1.379-.898.42-.166 1.051-.361 2.221-.421 1.275-.045 1.65-.06 4.859-.06l.045.03Zm0 3.678a6.162 6.162 0 1 0 0 12.324 6.162 6.162 0 1 0 0-12.324ZM12 16c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4Zm7.846-10.405a1.441 1.441 0 0 1-2.88 0 1.44 1.44 0 0 1 2.88 0Z" fill="#121314"></path></svg></a><a href="https://web.archive.org/web/20220911161327/https://www.linkedin.com/company/552285/admin/" target="_blank" rel="noopener noreferrer"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"><title>LinkedIn</title><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286h-.001ZM5.337 7.433a2.062 2.062 0 0 1-2.063-2.065 2.064 2.064 0 1 1 2.063 2.065Zm1.782 13.019H3.555V9h3.564v11.452ZM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003Z" fill="#121314"></path></svg></a><a href="https://web.archive.org/web/20220911161327/https://www.facebook.com/bitly" target="_blank" rel="noopener noreferrer"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"><title>Facebook</title><path d="M22.676 0H1.324C.593 0 0 .593 0 1.324v21.352C0 23.408.593 24 1.324 24h11.494v-9.294H9.689v-3.621h3.129V8.41c0-3.099 1.894-4.785 4.659-4.785 1.325 0 2.464.097 2.796.141v3.24h-1.921c-1.5 0-1.792.721-1.792 1.771v2.311h3.584l-.465 3.63H16.56V24h6.115c.733 0 1.325-.592 1.325-1.324V1.324C24 .593 23.408 0 22.676 0" fill="#121314"></path></svg></a></div></div></div></footer></main></div></div></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"markdownNav":[{"type":"header","route":"/docs/getting-started","path":"/docs/01_Getting_Started","name":"Getting Started","children":[{"type":"file","route":"/docs/getting-started/introduction","path":"/docs/01_Getting_Started/001_Introduction.md","name":"Introduction","children":null},{"type":"file","route":"/docs/getting-started/authentication","path":"/docs/01_Getting_Started/002_Authentication.md","name":"Authentication","children":null},{"type":"file","route":"/docs/getting-started/rate-limits","path":"/docs/01_Getting_Started/003_Rate_Limits.md","name":"Rate Limits","children":null},{"type":"file","route":"/docs/getting-started/troubleshooting-tips","path":"/docs/01_Getting_Started/004_Troubleshooting_\u0026_Tips.md","name":"Troubleshooting \u0026 Tips","children":null},{"type":"file","route":"/docs/getting-started/migrating-from-v3","path":"/docs/01_Getting_Started/005_Migrating_from_V3.md","name":"Migrating from V3","children":null}]},{"type":"header","route":"/docs/tutorials","path":"/docs/02_Tutorials","name":"Tutorials","children":[{"type":"file","route":"/docs/tutorials/create-a-test-account","path":"/docs/02_Tutorials/001_Create_a_Test_Account.md","name":"Create a Test Account","children":null},{"type":"file","route":"/docs/tutorials/shorten-customize-links","path":"/docs/02_Tutorials/002_Shorten_\u0026_Customize_Links.md","name":"Shorten \u0026 Customize Links","children":null},{"type":"file","route":"/docs/tutorials/retrieve-metrics","path":"/docs/02_Tutorials/003_Retrieve_Metrics.md","name":"Retrieve Metrics","children":null},{"type":"file","route":"/docs/tutorials/create-a-webhook","path":"/docs/02_Tutorials/004_Create_a_Webhook.md","name":"Create a Webhook","children":null},{"type":"file","route":"/docs/tutorials/integrate-bitly-in-your-app","path":"/docs/02_Tutorials/005_Integrate_Bitly_in_Your_App.md","name":"Integrate Bitly in Your App","children":null},{"type":"file","route":"/docs/tutorials/generate-qr-codes","path":"/docs/02_Tutorials/006_Generate_QR_Codes.md","name":"Generate QR Codes","children":null}]},{"type":"header","route":"/docs/sdks","path":"/docs/03_SDKs","name":"SDKs","children":[{"type":"file","route":"/docs/sdks/openapi-30","path":"/docs/03_SDKs/001_OpenAPI_3.0.md","name":"OpenAPI 3.0","children":null},{"type":"file","route":"/docs/sdks/android-sdk","path":"/docs/03_SDKs/002_Android_SDK.md","name":"Android SDK","children":null},{"type":"file","route":"/docs/sdks/ios-sdk","path":"/docs/03_SDKs/003_iOS_SDK.md","name":"iOS SDK","children":null}]}],"markdownSource":"# Bitly iOS SDK\n\n## Configure your iOS app\n\nBefore integrating the SDK you will need to configure your iOS app in Bitly. To do this, sign in to Bitly, open the profile menu, select **Settings**, click **Mobile deep links** below your account name, and click **Add a mobile application**.\n\nWhen creating the iOS app you will need to provide your Apple ID. The Apple ID is your Apple Team ID and bundle ID joined with a period (for example, 1A234H7ABC.com.yourdomain.YourApp). To get your Team ID, log in to [Apple鈥檚 Developer Portal](http://developer.apple.com/) and click **Membership** in the navigation menu. Your Team ID is displayed under Membership Details. If you choose to implement a Custom Scheme, you can also enter that during the app creation process.\n\nOnce the app is created, an app ID will be available on Bitly's app detail panel. Copy the ID for later in the setup.\n\nTo associate your app to your custom link domain in Bitly, you'll need to create an Apple Site Association File. To create the file, go to the profile menu, select **Settings**, and click **Custom domains** below your account name. Select your domain, click **Configure** in the Mobile behavior section, and then select the newly created iOS app. After saving the changes you can validate the file exists by going to https://\u003ci\u003e\u003c/i\u003eyourdomain.com/.well-known/apple-app-site-association.\n\n## Install the SDK\n\n### CocoaPods\n1. Add the following to your Podfile\n\n ```\n pod 'BitlySDK'\n ```\n2. Run the following to download and install the SDK\n\n ```\n pod install\n ```\n\n### Carthage\n1. Add the following to your Cartfile\n\n ```\n github \"bitly/bitly_ios_sdk_release\"\n ```\n2. Run the following to download and build the framework\n\n ```\n carthage update\n ```\n3. Drag the built `BitlySDK.framework` into your Xcode project\n\n### Configure the Universal Links\n1. In Xcode open your project file\n\n2. Go to the Capabilities tab\n\n3. Ensure that Associated Domains is enabled and expand it\n\n4. Click on the + button and add your domain as `applinks:yourdomain.com`\n\n5. Ensure that the yourprojectname.entitlements file is added to the appropriate build target\n\n### Configure the Custom Scheme\n1. In Xcode open your Info.plist\n\n2. Add a row for \"URL types\" as an array\n\n3. Add an entry to that array as \"URL Schemes\" also as an array\n\n4. Add a row with your custom scheme as the value\n\n\u003e Custom Schemes are the older way of handling deep linking. However having an app that supports both Universal Links and Custom Schemes allows Bitly to work with Facebook App Links, Facebook Ads and other apps that launch content utilizing Custom Scheme deep links.\n\n### Configure the SDK for Deep Links\n1. Import the SDK in your AppDelegate\n\n ```\n --swift--\n import BitlySDK\n --objectivec--\n #import \u003cBitlySDK/BitlySDK.h\u003e\n ```\n2. Initialize the SDK on application initialization\n ```\n --swift--\n func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -\u003e Bool {\n Bitly.initialize(\"YOUR_APP_ID\", supportedDomains:[\"yourdomain.com\",\"yourotherdomain.com\"], supportedSchemes:[\"yourscheme\"]) { response, error in\n // response provides a BitlyResponse object which contains the full URL information\n // response includes a status code\n // error provides any errors in retrieving information about the URL\n // Your custom logic goes here...\n }\n return true\n }\n --objectivec--\n - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n [Bitly initialize:@\"YOUR_APP_ID\" supportedDomains:[NSArray arrayWithObjects: @\"yourdomain.com\", @\"yourotherdomain.com\", nil] supportedDomains:[NSArray arrayWithObjects: @\"yourscheme\", nil] handler:^(BitlyResponse * response, NSString * error) {\n // response provides a BitlyResponse object which contains the full URL information\n // response includes a status code\n // error provides any errors in retrieving information about the URL\n // Your custom logic goes here...\n }];\n return YES;\n }\n ```\n\n \u003e By default the Bitly SDK utilizes the IDFV to identify the user. If you which to use the IDFA to track the user simply provide the `deviceId` to the appropriate method when initializing the SDK.\n \u003e You can also provide the access token for shortening with the `accessToken` provided to the initializing methods.\n\n3. Handle incoming links\n\n ```\n --swift--\n func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -\u003e Void) -\u003e Bool {\n return Bitly.handle(userActivity)\n }\n\n func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n return Bitly.handleOpen(url)\n }\n --objectivec--\n - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler {\n return [Bitly handleUserActivity:userActivity];\n }\n\n - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary\u003cUIApplicationOpenURLOptionsKey, id\u003e *)options {\n return [Bitly handleOpenUrl:url];\n }\n ```\n\n4. Retry on error\n ```\n --swift--\n Bitly.retryError(error)\n --objectivec--\n [Bitly retryError:error];\n ```\n\n \u003eIf there are any issues in handling a Universal Link the operation can be retried using the following line of code in your response handler from step 2\n\n## Configure the SDK for Shortening\n\n1. Configure an OAuth token for your app in your Bitly [settings](https://app.bitly.com/settings/api/).\n2. Import the SDK in your AppDelegate\n ```\n --swift--\n import BitlySDK\n --objectivec--\n #import \u003cBitlySDK/BitlySDK.h\u003e\n ```\n\n3. Initialize the SDK on application initialization\n ```\n --swift--\n func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -\u003e Bool {\n Bitly.initialize(\"YOUR_APP_ACCESS_TOKEN\")\n return true\n }\n --objectivec--\n - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n [Bitly initialize:@\"YOUR_APP_ACCESS_TOKEN\"];\n return YES;\n }\n ``` \n\n \u003e You can combine this initialization with the App Link initialization\n\n5. You can shorten from anywhere in your application\n ```\n --swift--\n Bitly.shorten(\"http://theurlyouwishtoshorten.com\") { response, error in\n // response provides a BitlyResponse object which contains the shortened Bitlink\n // response includes a status code\n // error provides any errors in retrieving information about the URL\n // Your custom logic goes here...\n }\n --objectivec--\n [Bitly shorten:@\"http://theurlyouwishtoshorten.com\" handler:^(BitlyResponse * response, NSString * error) {\n // response provides a BitlyResponse object which contains the shortened Bitlink\n // response includes a status code\n // error provides any errors in retrieving information about the URL\n // Your custom logic goes here...\n }];\n ```\n"},"__N_SSG":true},"page":"/docs/[...docs]","query":{"docs":["sdks","ios-sdk"]},"buildId":"63fcc1ddce08a26dd351c07b982972011d09e8a1","isFallback":false,"gsp":true,"scriptLoader":[]}</script></body></html><!-- FILE ARCHIVED ON 16:13:27 Sep 11, 2022 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 08:44:02 Feb 27, 2025. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). --> <!-- playback timings (ms): captures_list: 0.579 exclusion.robots: 0.028 exclusion.robots.policy: 0.016 esindex: 0.012 cdx.remote: 4.282 LoadShardBlock: 132.998 (3) PetaboxLoader3.datanode: 92.218 (5) PetaboxLoader3.resolve: 1332.066 (3) load_resource: 1335.427 (2) -->

Pages: 1 2 3 4 5 6 7 8 9 10