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
    146.3K+ Learners
    4.51  (13154)
    Programming Basics
    1 hrs
    Beginner
    196.1K+ Learners
    4.46  (13781)
    Coding Environment
    1 hrs
    Beginner
    21.8K+ Learners
    4.32  (513)
    JQuery Tutorial
    1 hrs
    Beginner
    12.5K+ Learners
    4.42  (777)
    What is IoT?
    1 hrs
    Beginner
    34.9K+ Learners
    4.47  (3522)
    Mongodb Tutorial
    2 hrs
    Beginner
    26.1K+ Learners
    4.53  (2530)
    Android App with Python
    2 hrs
    Beginner
    34.2K+ Learners
    4.41  (955)
    JavaScript Projects
    2 hrs
    Intermediate
    43.6K+ Learners
    4.48  (2112)
    HTML Attributes and Tags
    2 hrs
    Beginner
    53.2K+ Learners
    4.52  (3292)