iOS Core SDK
iOS Core SDK Documentation
Revisions:
Version | Details | Date | Author |
---|---|---|---|
1.0 | Initial version | 17/01/2022 | VW |
1.7.1 | Update includes: - Error returned from functions for API calls | 20/05/2022 | VW |
2.0.6 | Update includes: - Support for offers | 01/08/2022 | VW |
Prerequisites:
• Your application should be set up to use Cocoapods https://cocoapods.org
• You will require an active Apple developer account with signing capabilities
Getting Started
Follow these instructions to add the Kindred Core SDK to an existing iOS application.
For any questions or support with your integration, or to receive your API details, please email [email protected]
- Add the KindredSDK/Core to your podfile.
source 'https://github.com/kindred-app/Specs.git'
target 'your_app_name' do
pod 'KindredSDK/Core', '2.0.6'
end
-
In terminal, navigate to your project folder and run: -
pod install -
Head to your application info.plist and add a dictionary key named KindredKeyboard with 5 string values named, AuthClientId, AuthClientSecret, AuthSharedKey, BaseApiUrl, CDNUrl. This should look like the following: -
Note: Contact [email protected] to acquire your credentials.
<key>KindredKeyboard</key>
<dict>
<key>AuthClientId</key>
<string>YOUR_AUTH_CLIENT_ID</string>
<key>AuthClientSecret</key>
<string>YOUR_CLIENT_SECRET</string>
<key>AuthSharedKey</key>
<string>YOUR_SHARED_KEY</string>
<key>BaseApiUrl</key>
<string>https://api-partners.kindred.co</string>
<key>CDNUrl</key>
<string>https://cdn.kindred.co</string>
</dict>
- Import KindredSDK to your files before accessing the framework by adding the following to the top of your file
import KindredSDKCore
@import KindredSDKCore;
- Before using any services from the Core SDK, it must be configured once. Add the following to your file
@Injected(\.dealsService) private var dealsService: DealsServiceProtocol
@Injected(\.apiSettings) private var apiSettings: ApiSettingsProtocol
@Injected(\.settings) private var settings: CoreSettingsProtocol
@Injected(\.authenticationService) private var authenticationService: AuthenticationServiceProtocol
init() {
setupConfiguration()
authenticationService.authenticateSDK(completionHandler: { success, error in
if !success, let error = error {
debugPrint(error.errorDescription as Any)
}
})
}
func setupConfiguration() {
let coreConfiguration = CoreConfiguration()
apiSettings.setup(configuration: coreConfiguration)
settings.setStandardUserCountry()
settings.setStandardUserCurrency()
settings.setUserId(userId: "YOUR_USER_ID")
}
@implementation YourClassName {
id<CoreSettingsProtocol> settings;
id<DealsServiceProtocol> dealsService;
id<ApiSettingsProtocol> apiSettings;
id<UserServiceProtocol> userService;
id<AuthenticationServiceProtocol> authenticationService;
}
- (instancetype)init {
self = [super init];
settings = InjectedCore.settings;
dealsService = InjectedCore.dealsService;
apiSettings = InjectedCore.apiSettings;
userService = InjectedCore.userService;
authenticationService = InjectedCore.authenticationService;
[self setupConfiguration];
[authenticationService authenticateSDKWithCompletionHandler:^(BOOL success, KindredCoreError * _Nullable error) {
if (!success && error != nil) {
NSLog(@"%@", error.errorDescription);
}
}];
return self;
}
-(void)setupConfiguration {
CoreConfiguration *coreConfiguration = [CoreConfiguration new];
[apiSettings setupWithConfiguration:coreConfiguration];
[settings setStandardUserCountry];
[settings setStandardUserCurrency];
[settings setUserIdWithUserId: @"YOUR_USER_ID"];
}
Note: replace YOUR_USER_ID with your user ID value
- Using dependency injected services:
Swift: Use the following pattern to use dependency injected services
@Injected(\.settings) private var settings: CoreSettingsProtocol
Objective-C: Forward declare the service protocol and InjectedCore in the .h file
@protocol CoreSettingsProtocol;
@class InjectedCore;
Declare and initialise the variable in the .m file
@implementation YourClassName {
id<CoreSettingsProtocol> settings;
}
- (instancetype)init {
self = [super init];
settings = InjectedCore.settings;
}
Services
API Settings
The API settings is the first point of entry for the Core SDK. It allows you to pass in all of the configuration parameters that are used by the rest of the SDK.
Service protocol: ApiSettingsProtocol
You will need to create the CoreConfiguration object, and pass it through the following function
func setup(configuration: CoreConfiguration)
- (void)setupWithConfiguration:(CoreConfiguration * _Nonnull)configuration;
To get the url for logo image for a deal, use either of the following functions:
- with the logo name from deal as path
func getImageUrl(path: String) -> String
- (NSString * _Nonnull)getImageUrlWithPath:(NSString * _Nonnull)path
- with the logo name from deal as path and dimensions for the logo
func getImageUrl(path: String, parameters: [String: String]) -> URL?
let url = apiSettings.getImageUrl(path: path, parameters: ["height": "40", "width": "40"])
- (NSURL * _Nullable)getImageUrlWithPath:(NSString * _Nonnull)path parameters:(NSDictionary<NSString *, NSString *> * _Nonnull)parameters
NSURL *url = [apiSettings getImageUrlWithPath: path parameters: @{@"height" : @"40", @"width" : @"40"}];
Core Settings Service
The CoreSettings allows you to save and get various Core SDK related properties.
Service protocol: CoreSettingsProtocol
Use the following to save user's current country and currency depending on location
func setStandardUserCountry()
func setStandardUserCurrency()
- (void)setStandardUserCountry;
- (void)setStandardUserCurrency;
Use the following to store your user ID value
func setUserId(userId: String)
- (void)setUserIdWithUserId:(NSString * _Nonnull)userId;
Note: These settings are required for the framework to get relevant deals.
Authentication Service
This service allows you to authenticate your users against our backend, to search for deals and activate them.
Service protocol: AuthenticationServiceProtocol
You will need to call the following method after you have setup the configuration and before you start making requests through the DealsService.
func authenticateSDK(completionHandler: @escaping (Bool, KindredCoreError?) -> Void)
- (void)authenticateSDKWithCompletionHandler:(void (^ _Nonnull)(BOOL, KindredCoreError * _Nullable))completionHandler;
Deals Service
This service allows you to search deals and then get a unique tracking link for the activated deal.
Service protocol: DealsServiceProtocol
To search deals you will need a search term and a closure to consume the received deals.
Use the following to search deals
func searchForDeals(searchTerm: String, completionHandler: @escaping ([Deal]?, KindredCoreError?) -> Void)
- (void)searchForDealsWithSearchTerm:(NSString * _Nonnull)searchTerm completionHandler:(void (^ _Nonnull)(NSArray<Deal *> * _Nullable, KindredCoreError * _Nullable))completionHandler;
To activate a deal you will need the dealId and a closure to consume the received tracking url string
Use the following to get the deal link
func getDealUniqueTrackingLink(for dealID: String, couponAndOffer: CouponAndOffer?, completionHandler: @escaping(DealClick?, KindredCoreError?) -> Void)
- (void)getDealUniqueTrackingLinkFor:(NSString * _Nonnull)dealID couponAndOffer:(CouponAndOffer * _Nullable)couponAndOffer completionHandler:(void (^ _Nonnull)(DealClick * _Nullable, KindredCoreError * _Nullable))completionHandler;
Updated over 1 year ago