这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

infinitered/ProMotion-iap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ProMotion-iap

Gem Version Build Status

ProMotion-iap is in-app purchase notification support for the popular RubyMotion gem ProMotion.

Installation

gem 'ProMotion-iap'

Usage

PM::IAP::Product Class

The Product class is an abstraction layer that provides a simpler interface when working with a single IAP product. If you are dealing with multiple products you will want to use the IAP Module directly (documented below).

class PurchaseScreen < PM::Screen

  def on_load

    product = PM::IAP::Product.new("productid")

    product.retrieve do |product, error|
      # product looks something like the following
      {
        product_id:               "productid1",
        title:                    "title",
        description:              "description",
        price:                    <BigDecimal 0.99>,
        formatted_price:          "$0.99",
        price_locale:             <NSLocale>,
        downloadable:             false,
        download_content_lengths: <?>, # TODO: ?
        download_content_version: <?>, # TODO: ?
        product:                  <SKProduct>
      }
    end

    product.purchase do |status, transaction|
      case status
      when :in_progress
        # Usually do nothing, maybe a spinner
      when :deferred
        # Waiting on a prompt to the user
      when :purchased
        # Notify the user, update any affected UI elements
      when :canceled
        # They just canceled, no big deal.
      when :error
        # Failed to purchase
        transaction.error.localizedDescription # => error message
      end
    end

    product.restore do |status, product|
      if status == :restored
        # Update your UI, notify the user
      end
    end

  end
end

Product.new(product_id)

Stores the product_id for use in the instance methods.

retrieve(&callback)

Retrieves the product.

purchase(&callback)

Begins a purchase of the product.

restore(&callback)

Begins a restoration of the previously purchased product.

IAP Module

Include PM::IAP to add some in-app purchase methods to a screen, app delegate, or other class.

# app/screens/purchase_screen.rb
class PurchaseScreen < PM::Screen
  include PM::IAP

  def on_load

    retrieve_iaps [ "productid1", "productid2" ] do |products, error|
      # products looks something like the following
      [{
        product_id:               "productid1",
        title:                    "title",
        description:              "description",
        price:                    <BigDecimal 0.99>,
        formatted_price:          "$0.99",
        price_locale:             <NSLocale>,
        downloadable:             false,
        download_content_lengths: <?>, # TODO: ?
        download_content_version: <?>, # TODO: ?
        product:                  <SKProduct>
      }, {...}]
    end

    purchase_iap "productid" do |status, transaction|
      case status
      when :in_progress
        # Usually do nothing, maybe a spinner
      when :deferred
        # Waiting on a prompt to the user
      when :purchased
        # Notify the user, update any affected UI elements
      when :canceled
        # They just canceled, no big deal.
      when :error
        # Failed to purchase
        transaction.error.localizedDescription # => error message
      end
    end

    restore_iaps "productid" do |status, products|
      if status == :restored
        # Update your UI, notify the user
      end
    end


  end
end

retrieve_iaps(*product_ids, &callback)

Retrieves in-app purchase products in an array of mapped hashes. The callback method should accept products and error.

purchase_iaps(*product_ids, &callback)

Prompts the user to login to their Apple ID and complete the purchase. The callback method should accept status and transaction. The callback method will be called several times with the various statuses in the process. If more than one product_id is provided the callback method will be called several times per product with the applicable transaction.

restore_iaps(*product_ids, &callback)

Restores a previously purchased IAP to the user (for example if they have upgraded their device). This relies on the Apple ID the user enters at the prompt. Unfortunately, if there is no purchase to restore for the signed-in account, no error message is generated and will fail silently.

Find the Product ID here:

product id

Authors

| Contributor | Twitter | | Jamon Holmgren | @jamonholmgren | | Kevin VanGelder | @kevinvangelder |

Inspired By

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Make some specs pass
  5. Push to the branch (git iap origin my-new-feature)
  6. Create new Pull Request

About

In-app purchases for ProMotion!

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages