iOS

iOS In App Purchase

iOS In App Purchase

In iOS, In-App Purchase is a framework that allows us to incorporate a store into our app. The in-app purchase option in iOS is typically used to collect fees from consumers for extra features and content.

Assume you have a swift iOS application that allows users to access only a limited number of functions for free; however, if they want to access all of the app's features and content, they must pay. You can collect fees from users to enable all of our app's features and content by employing in-app purchases.

The Procedures Involved:

Step 1: Make sure you have a distinct App ID in iTunes Connect, then when you create the app, update it with the bundle ID and code signing in Xcode with the appropriate provisioning profile

Step 2: Make a new application and update the information on it. More information is available in Apple's guidelines on adding new apps.

Step 3: In the Manage In-App Purchase section of your application's page, add a new product for in-app purchase

Step 4: Make sure your application's bank details are set up. For in-app purchases to work, this must be configured. Create a test user account in your app's iTunes connect page using the Manage Users option

Step 5: The subsequent phases involve dealing with coding and designing a user interface for our In-App purchase

Step 6: Create a single-view application and fill in the bundle identifier from iTunes Connect

Step 7: As indicated below, update the ViewController.xib file


Step 8: Create IBOutlets for the three labels and the button naming them as productTitleLabel, productDescriptionLabel, productPriceLabel, and purchaseButton, respectively

Step 9: Select your project file, then select targets, and then add StoreKit.framework

Step 10: ViewController.h should be updated as follows:


Step 11: Make the following changes to ViewController.m:





Note

You must replace the productID you created for your In-App Purchase in kTutorialPointProductID. You can add several products by changing the NSSet of productIdentifiers in fetchAvailableProducts. Handle the purchase-related actions for the product IDs you add in the same way.

Output

We'll get the following output when you execute the application:



In the settings screen, make sure you've logged out of your account. Select Use Existing Apple ID when you click the Initiate Purchase button. Enter the username and password for your valid test account. In a few moments, you'll get the following alert.


You will receive the following notification once your product has been successfully purchased. Where you show this alert, you can view essential code for changing the application functionality.


Top course recommendations for you

    Software Testing Tutorial
    1 hrs
    Beginner
    143.6K+ Learners
    4.51  (12256)
    Programming Basics
    1 hrs
    Beginner
    192.9K+ Learners
    4.46  (12889)
    Coding Environment
    1 hrs
    Beginner
    21.5K+ Learners
    4.32  (470)
    JQuery Tutorial
    1 hrs
    Beginner
    12.3K+ Learners
    4.42  (734)
    What is IoT?
    1 hrs
    Beginner
    34.1K+ Learners
    4.46  (3111)
    Mongodb Tutorial
    2 hrs
    Beginner
    25.3K+ Learners
    4.54  (2253)
    Android App with Python
    2 hrs
    Beginner
    33.8K+ Learners
    4.41  (916)
    JavaScript Projects
    2 hrs
    Intermediate
    42.8K+ Learners
    4.5  (1898)
    HTML Attributes and Tags
    2 hrs
    Beginner
    52.6K+ Learners
    4.53  (3179)