Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. -(void)deleteKeyChain:(id)sender {
  2.  
  3. NSError *error = nil;
  4. NSLog(@"delete!!!!");
  5. [SFHFKeychainUtils deleteItemForUsername:@"someUser" andServiceName:kStoredData error:&error];
  6.  
  7. }
  8.  
  9. -(void)doFeature:(id)sender {
  10. [newPlayer pause];
  11. if ([self IAPItemPurchased]) {
  12.  
  13. // do the feature 2!
  14. // featureLabel.text = @"Feature: 2";
  15.  
  16. } else {
  17. // not purchased so show a view to prompt for purchase
  18. askToPurchase = [[UIAlertView alloc]
  19. initWithTitle:@"All Features"
  20. message:@"Tap refresh anytime to read latest 5 emails. To read all emails with no ads and to continue reading in the background, please purchase the full version of this app."
  21. delegate:self
  22. cancelButtonTitle:nil
  23. otherButtonTitles:@"OK",@"Later on", nil];
  24. askToPurchase.delegate = self;
  25. [askToPurchase show];
  26. [askToPurchase release];
  27. }
  28. }
  29.  
  30.  
  31. #pragma mark StoreKit Delegate
  32.  
  33. -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
  34. for (SKPaymentTransaction *transaction in transactions) {
  35. switch (transaction.transactionState) {
  36. case SKPaymentTransactionStatePurchasing:
  37.  
  38. // show wait view here
  39. // statusLabel.text = @"Processing...";
  40. break;
  41.  
  42. case SKPaymentTransactionStatePurchased:
  43.  
  44. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  45. // remove wait view and unlock feature 2
  46. // statusLabel.text = @"Done!";
  47. UIAlertView *tmp = [[UIAlertView alloc]
  48. initWithTitle:@"Complete"
  49. message:@"You now have the full version of Emails Aloud!!"
  50. delegate:self
  51. cancelButtonTitle:nil
  52. otherButtonTitles:@"Ok", nil];
  53. [tmp show];
  54. [tmp release];
  55.  
  56.  
  57. NSError *error = nil;
  58. [SFHFKeychainUtils storeUsername:@"someUser" andPassword:@"pass" forServiceName:kStoredData updateExisting:YES error:&error];
  59.  
  60. // apply purchase action - hide lock overlay and
  61. // [feature2Btn setBackgroundImage:nil forState:UIControlStateNormal];
  62.  
  63. // do other thing to enable the features
  64.  
  65. break;
  66.  
  67. case SKPaymentTransactionStateRestored:
  68. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  69. // remove wait view here
  70. // statusLabel.text = @"";
  71. break;
  72.  
  73. case SKPaymentTransactionStateFailed:
  74.  
  75. if (transaction.error.code != SKErrorPaymentCancelled) {
  76. NSLog(@"Error payment cancelled=%d",transaction.error.code);
  77. }
  78. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  79. // remove wait view here
  80. // statusLabel.text = @"Purchase Error!";
  81. break;
  82.  
  83. default:
  84. break;
  85. }
  86. }
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
  95. {
  96.  
  97. // remove wait view here
  98. // statusLabel.text = @"";
  99.  
  100. SKProduct *validProduct = nil;
  101. int count = [response.products count];
  102.  
  103. if (count>0) {
  104. validProduct = [response.products objectAtIndex:0];
  105. [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
  106. SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.myapp.shit"];
  107. [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  108. [[SKPaymentQueue defaultQueue] addPayment:payment];
  109.  
  110.  
  111. } else {
  112. UIAlertView *tmp = [[UIAlertView alloc]
  113. initWithTitle:@"Not Available"
  114. message:@"No products to purchase"
  115. delegate:self
  116. cancelButtonTitle:nil
  117. otherButtonTitles:@"Ok", nil];
  118. [tmp show];
  119. [tmp release];
  120. }
  121.  
  122.  
  123. }
  124.  
  125. -(void)requestDidFinish:(SKRequest *)request
  126. {
  127. [request release];
  128. }
  129.  
  130. -(void)request:(SKRequest *)request didFailWithError:(NSError *)error
  131. {
  132. NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
  133. }
  134. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  135.  
  136. if (alertView==askToPurchase) {
  137. if (buttonIndex==0) {
  138. // user tapped YES, but we need to check if IAP is enabled or not.
  139. if ([SKPaymentQueue canMakePayments]) {
  140.  
  141. SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.myapp.shit"]];
  142.  
  143. request.delegate = self;
  144. [request start];
  145.  
  146.  
  147. } else {
  148. UIAlertView *tmp = [[UIAlertView alloc]
  149. initWithTitle:@"Prohibited"
  150. message:@"Parental Control is enabled, cannot make a purchase!"
  151. delegate:self
  152. cancelButtonTitle:nil
  153. otherButtonTitles:@"Ok", nil];
  154. [tmp show];
  155. [tmp release];
  156. }
  157. }
  158. }
  159.  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement