这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 1 addition & 3 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
class AppDelegate < ProMotion::Delegate
class AppDelegate

def on_load(app, options)
end
end
30 changes: 16 additions & 14 deletions lib/ProMotion/iap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)