Last active
April 26, 2017 15:12
-
-
Save flashfabrixx/851332ab7e8728778be3a051bd058fd2 to your computer and use it in GitHub Desktop.
Version 1.9.22 to Version 1.10.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// This object will generate HTML requests for our WebView, that we will use to show the coupon | |
// details and fire the redemption | |
id theDelegate = [[UIApplication sharedApplication] delegate]; | |
self.requestFactory = [[theDelegate coupiesManager] requestFactoryForType:kCOUPIESRequestFactoryTypeHTML]; | |
// Load the details of the coupon and count the click | |
[webView loadRequest:[self.requestFactory requestForCouponWithId:(NSUInteger)self.coupon.couponId]]; | |
} | |
#pragma mark - Private methods | |
/** | |
* Some coupons can be redeemed by taking a photo of the receipt after buying a product. | |
* In this case, we open the photo-view in the COUPIES framework. | |
*/ | |
- (void)redeemCouponCashback:(id)sender { | |
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | |
id theDelegate = [[UIApplication sharedApplication] delegate]; | |
// Initialize COUPIESCashbackRedemptionViewController from Bundle and present it as a modal | |
UIStoryboard *cashbackStoryboard = [UIStoryboard storyboardWithName:@"COUPIESCashbackRedemptionMain" bundle:[NSBundle CoupiesResourcesBundle]]; | |
COUPIESCashbackRedemptionViewController *viewController = [cashbackStoryboard instantiateViewControllerWithIdentifier:@"COUPIESCashbackRedemptionViewController"]; | |
viewController.redemptionDelegate = self; | |
viewController.restService = [[theDelegate coupiesManager] newRestService]; | |
viewController.coupon = self.coupon; | |
[self presentViewController:viewController animated:YES completion:nil]; | |
} else { | |
//Error handling in case the device has no camera. In this case, those coupons cannot be redeemed. | |
} | |
} | |
/** | |
* This is a general action that triggers the redemption depending on the type of coupon | |
* It could be called from an IBAction, but in this case we intercept the click on "redeem now" in the | |
* WebView and trigger it from here. | |
*/ | |
- (IBAction)redeemCoupon { | |
// Only coupons can be redeemed. Offers and DailyDeals link to a website instead. | |
if ([self.coupon isKindOfClass:[COUPIESCoupon class]]) { | |
COUPIESCoupon *theCoupon = self.coupon; | |
if (theCoupon.action == kActionCashback) { | |
[self redeemCouponCashback:nil]; | |
} else { | |
// In this case we can directly load the green redemption view and need no ViewController in between. | |
[self didChooseRedeemDespiteNoSticker]; | |
} | |
} | |
} | |
#pragma mark COUPIESCashbackRedemptionViewControllerDelegate | |
- (void)didFinishPickingReceipt:(NSArray *)images withQuantity:(int)quantity { | |
[activityIndicatorView startAnimating]; | |
[webView loadRequest:[self.requestFactory requestForRedeemingCoupon:self.coupon withReceipt:images quantity:quantity]]; | |
} | |
#pragma mark UIWebViewDelegate | |
/** | |
* In this function, we intercept the click in "redeem now", so we can use the native camera feature | |
* to take a photo of a receipt where required. In case of a Cashback-Coupon, the HTML-representation redirects to a "preview"-page, | |
* where the picture is taken. Since this page is replaced by the native part of the framework, we intercept this as well. | |
*/ | |
- (BOOL)webView:(UIWebView *)inWebView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inNavigationType { | |
if (inRequest.URL.path && [inRequest.URL.path rangeOfString:@"/redemptions/cashback/preview"].location != NSNotFound) { | |
[self redeemCoupon]; | |
return NO; | |
} else { | |
return YES; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad { | |
id theDelegate = [[UIApplication sharedApplication] delegate]; | |
//This object will genereate HTML requests for our WebView, that we will use to show the coupon | |
//details and fire the redemption | |
self.requestFactory = [[theDelegate coupiesManager] requestFactoryForType:kCOUPIESRequestFactoryTypeHTML]; | |
} | |
- (void)viewWillAppear:(BOOL)inAnimated { | |
[super viewWillAppear:inAnimated]; | |
[webView loadRequest:[self.requestFactory requestForCouponWithId:self.coupon.couponId]]; //Load the details of the coupon and count the click | |
} | |
#pragma mark private methods | |
//Some coupons can be redeemed by taking a photo of the receipt after buying a product. | |
//In this case, we open the photo-view in the COUPIES-framework | |
- (void)redeemCouponCashback:(id)sender { | |
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | |
COUPIESCashbackRedemptionViewController *viewController = [[COUPIESCashbackRedemptionViewController alloc] initWithNibName:@"COUPIESCashbackRedemptionView" bundle:[NSBundle CoupiesResourcesBundle]]; | |
viewController.redemptionDelegate = self; | |
//Optionally set the number of remaining redemptions. This will let the user choose the number of coupons he wants to redeem | |
//at once on this receipt. If not set, COUPIES will decide. | |
viewController.remaining = self.coupon.remaining; | |
[self presentViewController:viewController animated:YES completion:nil]; | |
} else { | |
//Error handling in case the device has no camera. In this case, those coupons cannot be redeemed. | |
} | |
} | |
//This is a general action that triggers the redemption depending on the type of coupon | |
//It could be called from an IBAction, but in this case we intercept the click on "redeem now" in the | |
//WebView and trigger it from here | |
- (IBAction)redeemCoupon { | |
//Only coupons can be redeemd. Offers and DailyDeals link to a website instead. | |
if ([self.coupon isKindOfClass:[COUPIESCoupon class]]) { | |
COUPIESCoupon *theCoupon = (COUPIESCoupon *)self.coupon; | |
if (theCoupon.action == kActionCashback) { | |
[self redeemCouponCashback:nil]; | |
} else if (theCoupon.action == kActionRedeemInShop) { | |
if (theCoupon.closestLocationAcceptsSticker) { | |
[self redeemCouponViaSticker:nil]; | |
} else { | |
//In this case we can directly load the green redemption view and need no viewController in between. | |
[self didChooseRedeemDespiteNoSticker]; | |
} | |
} | |
} | |
} | |
#pragma mark COUPIESCashbackRedemptionViewControllerDelegate | |
-(void)didFinishPickingReceipt:(NSArray *)images withQuantity:(int)quantity { | |
didTriggerRedemption = YES; | |
[webView loadRequest:[self.requestFactory requestForRedeemingCoupon:self.coupon withReceipt:images quantity:quantity]]; | |
} | |
#pragma mark UIWebViewDelegate | |
//In this function, we intercept the click in "redeem now", so we can use the native camera feature | |
//to scan the COUPIES-Touchpoint or take a photo of a receipt where required | |
- (BOOL)webView:(UIWebView *)inWebView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inNavigationType { | |
NSURLRequest *theRequest = [self.requestFactory requestForRedeemingCoupon:self.coupon]; | |
//We compare the request to a generated redemption request. If it is the same (and was not just triggered by us) | |
//we intercept. | |
if ([theRequest.URL.path isEqualToString:inRequest.URL.path] && didTriggerRedemption == NO) { | |
[self redeemCoupon]; | |
return NO; | |
} else if ([inRequest.URL.path rangeOfString:@"/redemptions/cashback/preview"].location != NSNotFound) { | |
//In case of a Cashback-Coupon, the HTML-representation redirects to a "preview"-page, where the picture | |
//is taken. Since this page is replaced by the native part of the framework, we intercept this as well. | |
[self redeemCouponCashback:nil]; | |
return NO; | |
} else { | |
return YES; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Some coupons can be redeemed by taking a photo of the receipt after buying a product. | |
* In this case, we open the photo-view in the COUPIES-framework. | |
*/ | |
- (void)redeemCouponCashback:(id)sender { | |
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | |
id theDelegate = [[UIApplication sharedApplication] delegate]; | |
// Initialize COUPIESCashbackRedemptionViewController from Bundle and present it as a modal | |
UIStoryboard *cashbackStoryboard = [UIStoryboard storyboardWithName:@"COUPIESCashbackRedemptionMain" bundle:[NSBundle CoupiesResourcesBundle]]; | |
COUPIESCashbackRedemptionViewController *viewController = [cashbackStoryboard instantiateViewControllerWithIdentifier:@"COUPIESCashbackRedemptionViewController"]; | |
viewController.redemptionDelegate = self; | |
viewController.restService = [[theDelegate coupiesManager] newRestService]; | |
viewController.coupon = self.coupon; | |
[self presentViewController:viewController animated:YES completion:nil]; | |
} else { | |
// Error handling in case the device has no camera. In this case, those coupons cannot be redeemed. | |
} | |
} | |
// ... | |
- (void)didFinishPickingReceipt:(NSArray *)images withQuantity:(int)quantity { | |
[activityIndicatorView startAnimating]; | |
[webView loadRequest:[self.requestFactory requestForRedeemingCoupon:self.coupon withReceipt:images quantity:quantity]]; | |
} | |
// ... | |
#pragma mark UIWebViewDelegate | |
/** | |
* In this function, we intercept the click in "redeem now", so we can use the native camera feature | |
* to take a photo of a receipt where required. In case of a cashback coupon, the HTML-representation redirects to a | |
* "preview"-page, where the picture is taken. Since this page is replaced by the native part of the framework, | |
* we intercept this as well. | |
*/ | |
- (BOOL)webView:(UIWebView *)inWebView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inNavigationType { | |
if (inRequest.URL.path && [inRequest.URL.path rangeOfString:@"/redemptions/cashback/preview"].location != NSNotFound) { | |
[self redeemCoupon]; | |
return NO; | |
} else { | |
return YES; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Some coupons can be redeemed by taking a photo of the receipt after buying a product. | |
//In this case, we open the photo-view in the COUPIES-framework | |
- (void)redeemCouponCashback:(id)sender { | |
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | |
COUPIESCashbackRedemptionViewController *viewController = [[COUPIESCashbackRedemptionViewController alloc] initWithNibName:@"COUPIESCashbackRedemptionView" bundle:[NSBundle CoupiesResourcesBundle]]; | |
viewController.redemptionDelegate = self; | |
//Optionally set the number of remaining redemptions. This will let the user choose the number of coupons he wants to redeem | |
//at once on this receipt. If not set, COUPIES will decide. | |
viewController.remaining = self.coupon.remaining; | |
[self presentViewController:viewController animated:YES completion:nil]; | |
} else { | |
//Error handling in case the device has no camera. In this case, those coupons cannot be redeemed. | |
} | |
} | |
// ... | |
#pragma mark COUPIESCashbackRedemptionViewControllerDelegate | |
-(void)didFinishPickingReceipt:(NSArray *)images withQuantity:(int)quantity { | |
didTriggerRedemption = YES; | |
[webView loadRequest:[self.requestFactory requestForRedeemingCoupon:self.coupon withReceipt:images quantity:quantity]]; | |
} | |
// ... | |
#pragma mark UIWebViewDelegate | |
//In this function, we intercept the click in "redeem now", so we can use the native camera feature | |
//to scan the COUPIES-Touchpoint or take a photo of a receipt where required | |
- (BOOL)webView:(UIWebView *)inWebView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inNavigationType { | |
NSURLRequest *theRequest = [self.requestFactory requestForRedeemingCoupon:self.coupon]; | |
//We compare the request to a generated redemption request. If it is the same (and was not just triggered by us) | |
//we intercept. | |
if ([theRequest.URL.path isEqualToString:inRequest.URL.path] && didTriggerRedemption == NO) { | |
[self redeemCoupon]; | |
return NO; | |
} else if ([inRequest.URL.path rangeOfString:@"/redemptions/cashback/preview"].location != NSNotFound) { | |
//In case of a Cashback-Coupon, the HTML-representation redirects to a "preview"-page, where the picture | |
//is taken. Since this page is replaced by the native part of the framework, we intercept this as well. | |
[self redeemCouponCashback:nil]; | |
return NO; | |
} else { | |
return YES; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment