The iOS SDK of AfterShip API
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Aftership-iOS-SDK.xcodeproj
Aftership-iOS-SDK
Aftership-iOS-SDKTests
.gitignore
.swift-version
Aftership-iOS-SDK.podspec
LISENCE
Podfile
README.md

README.md

Aftership iOS SDK

AfterShip API SDK for iOS

Compatible with Aftership API v4

Installation

The recommended approach for installing Aftership iOS SDK is via the CocoaPods.

via CocoaPods

pod 'Aftership-iOS-SDK', '~> 1.1.9'

via source code

Developer can download source code here and integrate it with your project. Note that this project depends on RestKit for network and RXPromise for tests. Developers have to also include them for compilation.

Usage

Aftership iOS SDK is essentially a collection of requests to consume Aftership APIs. Before execute any request, a client must be prepared:

AftershipClient *client = [AftershipClient clientWithApiKey:@"YOUR_API_KEY"];

and then execute requests with it:

AftershipGetAllCouriersRequest *request = [AftershipGetAllCouriersRequest requestWithCompletionBlock:^(AftershipAbstractRequest *request,
          AftershipGetCouriersResponse *response,
          NSError *error) {
      if(error)
      {
        //handle failure
      } else
      {
        //handle results
      }      
  }];
[client executeRequest:request];

Tracking

Create tracking

    AftershipTracking *newTracking = [[AftershipTracking alloc] init];
    newTracking.trackingNumber = [NSString stringWithFormat:@"1111111111"];
    newTracking.slug = @"dhl";
    newTracking.emails = @[@"123@123.com"];
    newTracking.title = @"new tracking 1";
    AftershipCreateTrackingRequest *request = [AftershipCreateTrackingRequest requestWithTracking:newTracking completionBlock:^(AftershipCreateTrackingRequest *request, AftershipTracking *tracking, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        } else {
            NSLog(@"%@", tracking);
        }
    }];
    [client executeRequest:request];

Get tracking

    AftershipGetTrackingRequest *request = [AftershipGetTrackingRequest requestWithTrackingNumber:@"1111111111" slug:@"dhl" completionBlock:^(AftershipGetTrackingRequest *request, AftershipTracking *tracking, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        } else {
            NSLog(@"%@", tracking);
        }
    }];
    [client executeRequest:request];

Get trackings

    AftershipGetTrackingsRequest *request = [AftershipGetTrackingsRequest requestWithCompletionBlock:^(AftershipGetTrackingsRequest *request, AftershipGetTrackingsResponse *response, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        } else {
            NSLog(@"%@", response.trackings);
        }
    }];
    [client executeRequest:request];

Delete tracking

    AftershipDeleteTrackingRequest *request = [AftershipDeleteTrackingRequest requestWithTrackingNumber:@"1111111111" slug:@"dhl" completionBlock:^(AftershipDeleteTrackingRequest *request, AftershipTracking *tracking, NSError *error) {
        if (error) {
            NSLog(@"%@", error);
        } else {
            NSLog(@"%@", tracking);
        }
    }];
    [client executeRequest:request];