Giter Club home page Giter Club logo

bitly_ios_sdk_release's Introduction

Bitly iOS SDK

Supported Platforms Releases Latest pod release Carthage compatible Build Status Coverage Status

Getting Started

If you do not have any mobile apps setup in your Bitly account you will need to refer to the user guide for setting up deep links in your account.

Once you have setup your mobile app in your account, go to Your Settings -> Advanced -> Deep Link Applications. There you will find the Bitly App ID which needs to be included in your SDK configuration.

The domain referenced in the code examples below will be the Bitly Branded Domain which is enabled for Universal Links.

Enable Universal Links

To create the Apple site association file on your domain you must send your Apple app ID to your Bitly Account Manager to enable.

The Apple app ID is your team ID and bundle ID joined with a period (ex - 1A234H7ABC.com.yourdomain.YourApp). In the Apple’s Developer Portal your team ID appears on Organization Profile > Account Summary. When you enter the Member Center on http://developer.apple.com, click you name on the top right and click on “View Account” and you will find your team ID under the Developer Account Summary.

Install the SDK

CocoaPods

  1. Add the following to your Podfile
pod 'BitlySDK'
  1. Run the following to download and install the SDK
pod install

Carthage

  1. Add the following to your Cartfile
github "bitly/bitly_ios_sdk_release"
  1. Run the following to download and build the framework
carthage update
  1. Drag the built BitlySDK.framework into your Xcode project

Configure the Universal Links

  1. In Xcode open your project file
  2. Go to the Capabilities tab
  3. Ensure that Associated Domains is enabled and expand it
  4. Click on the + button and add your domain as applinks:yourdomain.com
  5. Ensure that the yourprojectname.entitlements file is added to the appropriate build target

Configure the SDK for Universal Links

  1. Import the SDK in your AppDelegate

Swift

import BitlySDK

Objective-C

#import <BitlySDK/BitlySDK.h>
  1. Initialize the SDK on application initialization

Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    Bitly.initialize("YOUR_APP_ID", supportedDomains:["yourdomain.com","yourotherdomain.com"], supportedSchemes:["yourscheme"]) { response, error in
        // response provides a BitlyResponse object which contains the full URL information
        // response includes a status code
        // error provides any errors in retrieving information about the URL
        // Your custom logic goes here...
    }
    return true
}

Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Bitly initialize:@"YOUR_APP_ID" supportedDomains:[NSArray arrayWithObjects: @"yourdomain.com", @"yourotherdomain.com", nil] supportedDomains:[NSArray arrayWithObjects: @"yourscheme", nil] handler:^(BitlyResponse * response, NSString * error) {
        // response provides a BitlyResponse object which contains the full URL information
        // response includes a status code
        // error provides any errors in retrieving information about the URL
        // Your custom logic goes here...
    }];
    return YES;
}

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. You can also provide the access token for shortening with the accessToken provided to the initializing methods.

  1. Handle incoming links

Swift

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    return Bitly.handle(userActivity)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return Bitly.handleOpen(url)
}

Objective-C

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler {
    return [Bitly handleUserActivity:userActivity];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
    return [Bitly handleOpenUrl:url];
}
  1. Retry on error

Swift

Bitly.retryError(error)

Objective-C

[Bitly retryError:error];

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

Configure the SDK for Shortening

  1. Configure an OAUTH token for your app http://bitly.com/a/oauth_apps
  2. Import the SDK in your AppDelegate

Swift

import BitlySDK

Objective-C

#import <BitlySDK/BitlySDK.h>
  1. Initialize the SDK on application initialization

Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    Bitly.initialize("YOUR_APP_ACCESS_TOKEN")
    return true
}

Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Bitly initialize:@"YOUR_APP_ACCESS_TOKEN"];
    return YES;
}
> You can combine this initialization with the App Link initialization
  1. You can shorten from anywhere in your application

Swift

  Bitly.shorten("http://theurlyouwishtoshorten.com") { response, error in
      // response provides a BitlyResponse object which contains the shortened Bitlink
      // response includes a status code
      // error provides any errors in retrieving information about the URL
      // Your custom logic goes here...
  }

Objective-C

  [Bitly shorten:@"http://theurlyouwishtoshorten.com" handler:^(BitlyResponse * response, NSString * error) {
      // response provides a BitlyResponse object which contains the shortened Bitlink
      // response includes a status code
      // error provides any errors in retrieving information about the URL
      // Your custom logic goes here...
  }];

bitly_ios_sdk_release's People

Contributors

bitlymobile avatar jctbitly avatar tux0010 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.