|ReleasedLast Release||Dec 2017|
|Apps WeekApps This Week||15|
|LOCLines of Code||0|
As an example, you are welcome to use our Template Project from Aviasales-iOS-SDK repo.
The easiest way is to use CocoaPods. It takes care of all required frameworks and third party dependencies:
pod 'AviasalesSDK', '~> 3.0.0'
We recommend to import
AviasalesSDK.h in each file where you use objects or protocols from SDK.
AviasalesSDK object before interaction with SDK like this:
AviasalesSDKInitialConfiguration *configuration = [AviasalesSDKInitialConfiguration configurationWithAPIToken:@"Your api token here" APILocale:[NSLocale currentLocale].localeIdentifier partnerMarker:@"Your partner marker here"]; [AviasalesSDK setupWithConfiguration:configuration];
Don't forget to replace two placeholders in this example with the actual values.
Specify search parameters using a
JRSDKSearchInfoBuilder object. Take a look at the example below.
Create simple object that describes new search:
JRSDKConfigurableSearchInfo *searchInfoBuilder = [[JRSDKSearchInfoBuilder alloc] init];
Set necessary parameters for the search (adults = 2 and travelClass = Business means that two adults would like to travel in business class):
searchInfoBuilder.adults = 2; searchInfoBuilder.travelClass = JRSDKTravelClassBusiness;
Set travel dates and airports (using airports storage from the SDK):
JRSDKTravelSegmentBuilder *travelSegmentBuilder = [JRSDKTravelSegmentBuilder new] travelSegmentBuilder.departureDate = [NSDate date]; travelSegmentBuilder.originAirport = [[AviasalesSDK sharedInstance].airportsStorage findAnythingByIATA:@"LED"]; travelSegmentBuilder.destinationAirport = [[AviasalesSDK sharedInstance].airportsStorage findAnythingByIATA:@"MOW"];
Save that travel segment to the search info:
searchInfoBuilder.travelSegments = [NSOrderedSet orderedSetWithObject:[travelSegmentBuilder build]];
And finally we can build a
JRSDKSearchInfo object for further usage:
JRSDKSearchInfo *searchInfo = [searchInfoBuilder build];
That's it. Search info is ready for search.
To perform search request use
SearchPerformer received from the SDK and send search info to it. Don't forget to store this performer somewhere during the search process.
JRSDKSearchPerformer *searchPerformer = [[AviasalesSDK sharedInstance] createSearchPerformer];
To retrieve live and final search results set delegate (
JRSDKSearchPerformerDelegate) to this search performer:
searchPerformer.delegate = self;
This delegate requires to implement three methods: First one is called when results are ready to be displayed (SDK continues to wait for more results after this call and in some very rare cases it can get cheaper tickets for this request):
- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFinishRegularSearch:(JRSDKSearchInfo *)searchInfo withResult:(JRSDKSearchResult *)result andMetropolitanResult:(JRSDKSearchResult *)metropolitanResult;
Second needed to receive error if it occures during the search
- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFailSearchWithError:(NSError *)error connection:(JRServerAPIConnection *)connection;
And the third one needed to understand when the process is finished. After its call, you can release search performer because it is not recyclable.
- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFinalizeSearchWithInfo:(id<JRSDKSearchInfo>)searchInfo error:(NSError *)error;
Optional method is called when a new chunk of tickets is received from server:
- (void)searchPerformer:(JRSDKSearchPerformer *)searchPerformer didFindSomeTickets:(JRSDKSearchResultsChunk *)newTickets inSearchInfo:(JRSDKSearchInfo *)searchInfo temporaryResult:(JRSDKSearchResult *)temporaryResult temporaryMetropolitanResult:(JRSDKSearchResult *)temporaryMetropolitanResult;
Start search performing:
[searchPerformer performSearchWithSearchInfo:searchInfo includeResultsInEnglish:YES];
Search results are received as
JRSDKSearchResult objects. If a search is started with a specific airport as a parameter,
metropolitanResult will be different — tha last one will contain tickets to any airport of the given city.
AviasalesSDKPurchasePerformer is object used to perform ticket purchase. Each ticket contains different proposals from different agencies, you should use one of them as an input parameter.
Create performer using price and searchId (
JRSDKSearchResult > JRSDKSearchResultInfo) that was returned with the search result.
- (instancetype)initWithPrice:(id <JRSDKPrice>)price searchId:(NSString *)searchId;
Generate a link for the purchase:
- (void)performWithDelegate:(id <AviasalesSDKPurchasePerformerDelegate>)delegate;
Open link received by delegate in browser to provide user purchase form.
Aviasales SDK allows you to generate additional revenue by displaying advertisements to your users.
AviasalesSDKAdsManager object received like:
to load information for the waiting screen
- (void)loadAdsViewForWaitingScreenWithSearchInfo:(id <JRSDKSearchInfo>)searchInfo completion:(AviasalesSDKAdsManagerCompletion)completion;
or for the search results list with your search info.
- (void)loadAdsViewForSearchResultsWithSearchInfo:(id <JRSDKSearchInfo>)searchInfo completion:(AviasalesSDKAdsManagerCompletion)completion;
After appropriate method call you will receive
AviasalesSDKAdsView with ads.
|Name||How to retrieve object||Description|
||Finds airport by IATA, provides a list of airports|
||Finds airports by string|
||Finds nearest airports to the current user.|
||Loads and displays advertisement according to search parameters|
||Util methods that help you to work with SDK objects|