GithubHelp home page GithubHelp logo

svanichkin / store Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 203 KB

A simple but unusually powerful class for working with all types of in-app purchases (consumable, nonConsumable, autoRenewable, nonRenewing).

License: Apache License 2.0

Objective-C 94.11% Ruby 5.89%

store's Introduction

Store

A simple but unusually powerful class for working with all types of in-app purchases (consumable, nonConsumable, autoRenewable, nonRenewing).

The class itself ensures that the application is unloaded or loaded, does all the necessary actions. When the class has downloaded the purchases, made the recovery of purchases and checked their relevance on the server Apple, the isReady property will become YES.

Initialization in AppDelegate:

  -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary  *)launchOptions
  {
      [Store
       setupWithSharedSecret:@"shared secret key fot inapp"
       storeItems:@[@"com.purchase.money".storeItem.consumable, @"com.purchase.month".storeItem.autoRenewableSubscription]
       completion:^(NSError *error)
      {
          if (error)
              return;

          if (Store.storeItemsPurchased.count == 0)
              [self.window.rootViewController
               presentViewController:MyStoreController
               animated:YES
               completion:nil];
      }];

      return YES;
  }

What are identifiers with access to NSString.storeItem for?

  1. For initialization, as described above;
  2. To access a purchase through an identifier, bypassing the long constructions of a search or access to classes;
  3. To easily add shopping pages to templates.

A call to a purchase can be made through an identifier, for example:

NSString *title = @"com.purchase.money".storeItem.title;

And then assign a title to the UIButton...

Usually some window is used to display the shopping list, for example, we have a ready-made template in the storyboard, then you can create a rule in which cases you need to show this window (or for example several different windows, or create several different conditions).

  [Store setLockRules:^(UIViewController *controller)
  {
      // For example consumable purchase
      NSArray <StoreItem *> *consumable =
      [Store storeItemsWithType:StoreItemTypeConsumable];

      if (consumable.count == 0); // if not consumable purchase, show store controller
      {
          [controller
           presentViewController:MyStoreController
           animated:YES
           completion:nil];

          return YES; // lock
      }

      else // If there is, we will spend it
          [consumable.firstObject consumablePurchaseReset];

      return NO; // no lock
  }];

In the place where you need to spend (or show the shopping window, if not one), just add the code:

  -(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  {
      return
      ![Store isLockWithController:self];
  }

In this case, when you go to the page, the check specified in the setLockRules block is performed: it will be spent one consumable purchase and the user will follow shouldPerformSegueWithIdentifier: either there will be no transition, and instead the MyStoreController controller will be shown, from the setRules block.

isLockWithController: returns YES / NO, based on return from setLockRules:

You can also protect the application from hacking, by transferring check check to your server. Or such a service allow you to do this, such as Apphud. In this method, you can safely cause a synchronous request or asynchronous. For instance:

  [Store checkRawReceiptString:^NSDictionary *(BOOL sandbox)
  {
      __block NSDictionary *rawJSON = nil;
    
      dispatch_semaphore_t sem =
      dispatch_semaphore_create(0);
    
      [Apphud fetchRawReceiptInfo:^(ApphudReceipt *receipt)
      {
          rawJSON =
          receipt.rawJSON;
        
          dispatch_semaphore_signal(sem);
      }];
    
      dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
    
      return rawJSON;
  }];

store's People

Contributors

svanichkin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.