Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Swift UIKit example of how to use SwiftTipJar package

NotificationsYou must be signed in to change notification settings

dkasaj/SwiftTipJar-UIKit-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ThisUIKit sample code demonstrates ease of use forSwiftTipJar - an open source package.

There is alsoSwiftUI sample code (same functionality).

Tip jars on Apple platforms are a concept of letting users make in-app purchases to show appreciation for the app/developer. These don't actually unlock any additional features.

Demo app screenshots

Choice of tipsSystem UI for purchasingSuccessful purchaseThank you message
Choice of tipsSystem UI for purchasingSuccessful purchaseThank you message

Usage

  1. Init TipJar with identifiers for In-App Purchases you wish to offer
  2. Make TipJar observe StoreKit's payment queue
  3. Set up code blocks to run after products information is received - from Xcode (when using StoreKit Configuration file) or from App Store Connect over the network - and after a transaction succeeds or fails.
  4. Request the products information
// #1lettipJar=SwiftTipJar(tipsIdentifiers:Set(["com.test.smallTip","com.test.mediumTip","com.test.largeTip","com.test.hugeTip"]))overridefunc viewDidLoad(){  super.viewDidLoad()  // #2  tipJar.startObservingPaymentQueue()  // #3  tipJar.productsReceivedBlock= setupButtons  tipJar.transactionSuccessfulBlock= showThankYou  // #4  tipJar.productsRequest?.start()}
  1. As soon as tipJar finds out about the products, it runs publishestips, an array of Tip objects that supplies you withdisplayName anddisplayPrice, in local language and currency, and runsproductsReceivedBlock. Tips array has been sorted by price, ascending. Products that haven't been configured with a name and/or price are simply omitted from this array.
@Publishedpublicprivate(set)vartips:[Tip]=[]
publicfinalclassTip{publicvaridentifier:String=""publicvardisplayName:String=""publicvardisplayPrice:String=""    /// TipJar uses this to quickly check if it should include this Tip in its published array.varisValid:Bool{return !identifier.isEmpty && !displayName.isEmpty && !displayPrice.isEmpty}}
  1. Assign any code you want to run after a successful purchase totransactionSuccessfulBlock, and similarly any code you want to run after a failed purchase (user clicked Cancel instead of Purchase) totransactionFailedBlock.With tip jars, it's even natural to do nothing if a transaction fails.
  2. Set up button(s) to initiate a purchase to trigger the actioninitiatePurchase(productIdentifier:)
@objcfunc userDidTapButton(_ sender:UIButton?){guardlet identifier= sender?.accessibilityIdentifierelse{return}  tipJar.initiatePurchase(productIdentifier: identifier)}

Troubleshooting

Q: I've set up IAPs in a StoreKit Configuration file, but nothing is showing up in the demo app

A: Edit Scheme > Options, and check that you have the correct StoreKit Configuration selected

Q: I've set up IAPs in StoreKit Configuration file, some are showing up in demo app, but not all

A: Check that TipJar's init is called with all relevant identifiers; check identifiers for any spelling errors. Check that you've provided the name and price for every IAP you want to see in the demo app.

About

Swift UIKit example of how to use SwiftTipJar package

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp