Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from jinSasaki/update-example
Browse files Browse the repository at this point in the history
Update example
  • Loading branch information
jinSasaki authored Aug 12, 2021
2 parents 392e05e + fcd669e commit 5ad2e9e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
excluded:
- Example
- Examples

disabled_rules:
- xctfail_message
- nesting
file_length:
- 600 # warning
- 800 # warning
- 1000 # error
line_length:
- 200 # warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/jinSasaki/InAppPurchase.git",
"state": {
"branch": "master",
"revision": "25c9e5fdb9d3263c4c8628c49ca94f6257874d45",
"revision": "392e05ecf7aad96e12c95bccfda630380581ade7",
"version": null
}
}
Expand Down
35 changes: 23 additions & 12 deletions Examples/Custom/CustomInAppPurchaseSample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum Constant {

final class ViewController: UIViewController {

var responses: [PaymentResponse] = []
var transactions: [PaymentTransaction] = []

@IBOutlet private weak var tableView: UITableView! {
didSet {
Expand All @@ -27,6 +27,14 @@ final class ViewController: UIViewController {
}
}

override func viewDidLoad() {
super.viewDidLoad()

Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
self?.reloadTransactions()
}
}

@IBAction func tapPurchaseCoin() {
let id = Constant.Product.coin
InAppPurchase.custom.purchase(productIdentifier: id) { [weak self] result in
Expand Down Expand Up @@ -59,36 +67,39 @@ final class ViewController: UIViewController {
case .deferred:
print("[DEFERRED] \(response.transaction.transactionIdentifier ?? "nil")")
}
self.responses.append(response)
self.tableView.reloadData()
self.reloadTransactions()
case .failure(let error):
print(error)
}
}

private func reloadTransactions() {
self.transactions = InAppPurchase.custom.transactions
self.tableView.reloadData()
}
}

extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return responses.count
return transactions.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "default")
let response = responses[indexPath.row]
cell.textLabel?.text = "\(response.transaction.productIdentifier) \(response.transaction.transactionIdentifier ?? "-")"
cell.detailTextLabel?.text = "\(response.state)"
let transaction = transactions[indexPath.row]
cell.textLabel?.text = "\(transaction.productIdentifier) \(transaction.transactionIdentifier ?? "-")"
cell.detailTextLabel?.text = "\(transaction.state)"
return cell
}
}

extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let response = responses[indexPath.row]
let alert = UIAlertController(title: "Finish transaction?", message: response.transaction.transactionIdentifier, preferredStyle: .alert)
let transaction = transactions[indexPath.row]
let alert = UIAlertController(title: "Finish transaction?", message: transaction.transactionIdentifier, preferredStyle: .alert)
alert.addAction(.init(title: "Finish", style: .default, handler: { [weak self] _ in
InAppPurchase.custom.finish(transaction: response.transaction)
self?.responses.removeAll(where: { $0.transaction.transactionIdentifier == response.transaction.transactionIdentifier })
self?.tableView.reloadData()
InAppPurchase.custom.finish(transaction: transaction)
self?.reloadTransactions()
}))
alert.addAction(.init(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
Expand Down
17 changes: 1 addition & 16 deletions InAppPurchase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@
938BFA751F5E8411006A4C2A /* Sources */,
938BFA761F5E8411006A4C2A /* Frameworks */,
938BFA771F5E8411006A4C2A /* Resources */,
939016A91F72D44E0061C83B /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -423,20 +422,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
939016A91F72D44E0061C83B /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
93C3297D1F5EA27F00F7A5E7 /* Swiftlint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -449,7 +434,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ let package = Package(
],
products: [
.library(name: "InAppPurchase", targets: ["InAppPurchase"]),
.library(name: "InAppPurchaseStubs", targets: ["InAppPurchaseStubs"]),
.library(name: "InAppPurchaseStubs", targets: ["InAppPurchaseStubs"])
],
targets: [
.target(name: "InAppPurchase", path: "Sources"),
.target(name: "InAppPurchaseStubs", dependencies: ["InAppPurchase"], path: "InAppPurchaseStubs"),
.testTarget(name: "InAppPurchaseTests", dependencies: ["InAppPurchase", "InAppPurchaseStubs"], path: "Tests"),
.testTarget(name: "InAppPurchaseTests", dependencies: ["InAppPurchase", "InAppPurchaseStubs"], path: "Tests")
],
swiftLanguageVersions: [.v5]
)

0 comments on commit 5ad2e9e

Please sign in to comment.