Objective-C Setup
For Swift setup see Swift Setup.
Create / Setup a
VouchrConfig
with your values. You can alternatively use a plist file to provide values. SeeVouchrConfig
for details.VouchrConfig *vouchrConfig = [VouchrConfig config]; vouchrConfig.serverUrl = @"https://www.vouchrsdk.com"; // This will be given to you by Vouchr vouchrConfig.sdkString = @"SDK_STRING"; // This will be given to you by Vouchr
Instantiate a
VouchrEngine
with your preferred dependencies and theVouchrConfig
you created.VouchrEngine *vouchrEngineSDK = [VouchrEngine vouchrEngineWithConfig:vouchrConfig builder:^(VouchrEngineBuilder *builder) { // override any default managers here // eg. builder.networkManager = [YourNetworkManager new]; }];
Instantiate a
VoucherCreationManager
:VoucherCreationManager *creationManager = [VoucherCreationManager voucherCreationManagerWithBuilder:^(VoucherCreationManagerBuilder *builder) { // override any default settings // eg. builder.fullScreenLoadingView = [[SurpriiseLoadingView alloc] initWithFrame:CGRectZero]; }];
Instantiate a
VoucherCreationFlowCoordinator
:VoucherCreationFlowCoordinator *voucherCreationFlowCoordinator = [VoucherCreationFlowCoordinator voucherCreationFlowCoordinatorWithManager:creationManager vouchrTheme:[VouchrConfig defaultVouchrTheme] delegate:self];
Implement the
VoucherCreationFlowDelegate
methods that is passed into theVoucherCreationFlowCoordinator
. Most are optional. The two that must be implemented:- (void)voucherCreationShowPaymentOnViewController:(UIViewController *)viewController forVoucher:(Voucher *)voucher onCompletion:(void(^)(NSDictionary *paymentInfo, NSError *error))completion { // get payment info here for the voucher // MUST CALL completion block when finished completion(nil, nil); } - (void)showLoginOnViewController:(UIViewController *)viewController onCompletion:(void(^)(NSError *error))completion { // log in the user here // if a login view controller needs to be presented, present it on viewController. // MUST CALL to userManager loginWithCredentials:refreshTokenClient:onSuccess:onError before calling completion. // MUST CALL completion block when finished completion(nil); }
Instantiate
PersonalizationOption
s for all personalizations that will be available to the user.NSMutableArray <PersonalizationOption *> *personalizationOptions = [NSMutableArray new]; [personalizationOptions addObject:[RecipientPersonalizationOption recipientPersonalizationOptionWithBuilder:^(RecipientPersonalizationOptionBuilder *builder) { builder.vouchrTheme = [self recipientVouchrTheme]; builder.canChangeUnwrapDate = YES; builder.canMakeItARace = YES; builder.canSendToEmail = YES; builder.canSendToPhoneNumber = YES; }]]; [personalizationOptions addObject:[TitlePersonalizationOption titlePersonalizationOptionWithBuilder:^(TitlePersonalizationOptionBuilder *builder) { }]]; [personalizationOptions addObject:[PhotoPersonalizationOption photoPersonalizationOptionWithBuilder:^(PhotoPersonalizationOptionBuilder *builder) { builder.canAddMultiple = NO; builder.canUploadPhotos = NO; builder.canAddGoogleImages = YES; builder.canTakePhotos = YES; builder.suggestedSearchTerms = @[@"one", @"two", @"three"]; }]];
Launch the Voucher Creation flow:
[voucherCreationFlowCoordinator startFlowOnViewController:self.selectedViewController personalizationOptions:personalizationOptions];