diff --git a/Rakefile b/Rakefile index c459c35..583bc75 100644 --- a/Rakefile +++ b/Rakefile @@ -3,7 +3,6 @@ $:.unshift("/Library/RubyMotion/lib") require 'motion/project/template/ios' require 'bundler' Bundler.require(:development) -require 'ProMotion' require 'ProMotion-iap' Motion::Project::App.setup do |app| diff --git a/app/app_delegate.rb b/app/app_delegate.rb index 6400a5d..de8a48d 100644 --- a/app/app_delegate.rb +++ b/app/app_delegate.rb @@ -1,5 +1,3 @@ -class AppDelegate < ProMotion::Delegate +class AppDelegate - def on_load(app, options) - end end diff --git a/lib/ProMotion/iap.rb b/lib/ProMotion/iap.rb index 9e579f8..aa2f96e 100644 --- a/lib/ProMotion/iap.rb +++ b/lib/ProMotion/iap.rb @@ -2,7 +2,7 @@ module ProMotion module IAP attr_accessor :completion_handlers - def purchase_iap(product_id, &callback) + def purchase_iaps(product_id, &callback) iap_setup retrieve_iaps product_id do |products| products.each do |product| @@ -12,6 +12,7 @@ def purchase_iap(product_id, &callback) end end end + alias purchase_iap purchase_iaps def restore_iaps(product_id, &callback) iap_setup @@ -22,6 +23,7 @@ def restore_iaps(product_id, &callback) end end end + alias restore_iap restore_iaps def retrieve_iaps(*product_ids, &callback) iap_setup @@ -76,6 +78,19 @@ def formatted_iap_price(price, price_locale) num_formatter.stringFromNumber price end + def iap_callback(status, transaction, finish=false) + product_id = transaction.payment.productIdentifier + if self.completion_handlers["purchase-#{product_id}"] + self.completion_handlers["purchase-#{product_id}"].call status, transaction + self.completion_handlers["purchase-#{product_id}"] = nil if finish + end + if self.completion_handlers["restore-#{product_id}"] + self.completion_handlers["restore-#{product_id}"].call status, transaction + self.completion_handlers["restore-#{product_id}"] = nil if finish + end + SKPaymentQueue.defaultQueue.finishTransaction(transaction) if finish + end + public # SKProductsRequestDelegate methods @@ -117,19 +132,6 @@ def paymentQueue(_, updatedTransactions:transactions) end end - def iap_callback(status, transaction, finish=false) - product_id = transaction.payment.productIdentifier - if self.completion_handlers["purchase-#{product_id}"] - self.completion_handlers["purchase-#{product_id}"].call status, transaction - self.completion_handlers["purchase-#{product_id}"] = nil if finish - end - if self.completion_handlers["restore-#{product_id}"] - self.completion_handlers["restore-#{product_id}"].call status, transaction - self.completion_handlers["restore-#{product_id}"] = nil if finish - end - SKPaymentQueue.defaultQueue.finishTransaction(transaction) if finish - end - end end ::PM = ProMotion unless defined?(::PM)