iOS Tutorial iStore - In App Purchases

Discussion in 'iOS Tutorials' started by Erel, Jan 12, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    The iStore library allows you to use the store In-App Purchases features inside your app.
    You can let the user purchase digital products from inside your app.

    (Unsurprisingly) the configuration required is a bit tedious.

    In order to test this feature (and later release it) you need to create an app in iTunes Connect and create one or more in-app products. You don't need to actually upload the app binary file however you do need to fill all the fields and prepare the app. Later you can change them as needed.

    After you've created an app placeholder in iTunes you need to carefully follow these instructions:
    https://developer.apple.com/library/ios/technotes/tn2259/_index.html

    The main steps:
    1. iOS Paid Applications contract should appear under "contracts in effect".
    2. You need to create an explicit App Id (without wildcards) and download a new provision file.
      You can use #ProvisionFile to tell the IDE which provision file should be used.
    3. Create a test account as explained in the tech note. Later you will sign out of the store from the Settings app. Note that you should not sign in to the store with the test account from the Settings app. The test account should only be used inside your app.
    4. Create one or more in-app products and make sure not to upload a screenshot during development.
    iStore library supports two types of products: consumable and non-consumable products.
    Consumable - The user can purchase these products multiple times. For example in a game a user can purchase extra health or coins.
    Non-consumable - The user can purchase such products once. For example the user can use such product to permanently remove ads from the app. If you are selling such products then you need to allow the user to restore such products if the user switches to a different device (with a "restore transactions" button).

    Code

    The code is quite simple.
    First you initialize a Store object and check whether the device supports this feature:
    Code:
    Dim MyStore As Store 'declare it in Process Globals
    ...
    MyStore.Initialize(
    "MyStore")
    If MyStore.CanMakePayments = False Then ...
    Later you can request a payment and then handle the PurchaseCompleted event:
    Code:
    MyStore.RequestPayment("product.id")

    Sub MyStore_PurchaseCompleted (Success As Boolean, Product As Purchase)
       
    Log("Purchase completed")
       
    If Product.IsInitialized Then
         
    Log("Product: " & Product.ProductIdentifier & ", date=" & DateTime.Time(Product.TransactionDate) & _
           
    ", Transaction identifier=" & Product.TransactionIdentifier)
       
    End If
       
    Log("Success = " & Success)
    End Sub
    The user will be asked to log in to his store account (use the test account here) and approve the purchase.

    Restoring non-consumable purchases

    As noted above, if you are selling such products then you are expected to provide a way for the user to restore completed transaction.
    Once the user requests to restore transactions you need to call MyStore.RestoreTransactions. The PurchaseCompleted event will be raised for each previous purchase of non-consumable products.
    The TransactionsRestored event will be raised at the end.

    Note that the user might be asked to log in to his account, therefore you shouldn't call this method when the apps starts to find existing purchases (unlike the Android library).
     
    Last edited: Mar 6, 2016
    yiankos1, MarcoRome, Ohanian and 3 others like this.
  2. tufanv

    tufanv Expert Licensed User

    was waiting for this ! TY
     
  3. ilan

    ilan Expert Licensed User

    Great!
     
    Last edited: Feb 8, 2015
  4. tucano2000

    tucano2000 Active Member Licensed User

    Why do I have this error message in b4i using hosted mac builder ?

    Error occurred on line: 0 (main)
    Class not found: B4IStore
    Stack Trace: (
    CoreFoundation <redacted> + 154
    libobjc.A.dylib objc_exception_throw + 38
    CoreFoundation <redacted> + 0
    iStore Test -[B4IShell createObject:] + 206
    iStore Test -[B4IShell raiseEventImpl:method:args::] + 1910
    iStore Test -[B4IShellBI raiseEvent:event:params:] + 1316
    iStore Test -[B4IStaticModule initializeModule] + 534
    iStore Test -[b4i_main initializeStaticModules] + 84
    iStore Test -[B4IShellBI raiseEvent:event:params:] + 228
    iStore Test __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
    libdispatch.dylib <redacted> + 10
    libdispatch.dylib <redacted> + 22
    libdispatch.dylib <redacted> + 278
    CoreFoundation <redacted> + 8
    CoreFoundation <redacted> + 1300
    CoreFoundation CFRunLoopRunSpecific + 522
    CoreFoundation CFRunLoopRunInMode + 106
    GraphicsServices GSEventRunModal + 138
    UIKit UIApplicationMain + 1136
    iStore Test main + 116
    libdyld.dylib <redacted> + 2
    )
    Application_Start
    Application_Active
     
    Last edited: Jan 20, 2015
  5. Erel

    Erel Administrator Staff Member Licensed User

    Are you using a local mac builder?
     
  6. tucano2000

    tucano2000 Active Member Licensed User

    Hosted mac builder
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Fixed. It will now work.
     
  8. tucano2000

    tucano2000 Active Member Licensed User

    Thanks Erel. It is working now.
     
  9. kurng

    kurng Member Licensed User

    Any one have complete code for example .
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    All the required code appears in the first post. You just need to add it to your project.
     
  11. kurng

    kurng Member Licensed User

    Thk Erel in time I see. Ha ha
     
  12. ilan

    ilan Expert Licensed User

    hi,

    i have followed the instruction and i am trying to make a purchase (debug mode)

    this is the log i get

    is success false because i am in debug mode??

    i also check on app start if can make purchase and app can...

     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Have you already "purchased" this product? The user can only purchase each non-consumable product once.
     
  14. ilan

    ilan Expert Licensed User

    no i have not purchase it (and its a consumable product) so multi time purchase like chips for poker game...
    and when i try it get success = false and nothing happens (no direct to appstore...)
     
  15. tufanv

    tufanv Expert Licensed User

    Erel,

    What is the screenshot for ? after we complete our work we will get screenshot of what ? and upload it for review =?
     
  16. ilan

    ilan Expert Licensed User

    uppssss. sorry erel it is working
    i tried to make a purchase with my apple account and i missed the part to create a sandbox (test account)

    thank you very much for this lib, now i only need a big containers to store the money i will make with iStore... :D
     
    Last edited: Feb 1, 2015
  17. tufanv

    tufanv Expert Licensed User

    Do you have idea about the screenshot Ilan ? :)
     
  18. ilan

    ilan Expert Licensed User


    Do you mean the screenshot that we need to add to the in app purchase??

    when you create a new in app purchase product you must upload a screenshot (i have uploaded a screenshot of my purchase screen)
    i am not sure for what they need it but you know "APPLE" :rolleyes:
     
    Last edited: Feb 3, 2015
  19. tufanv

    tufanv Expert Licensed User

    yeah I am talking about that. It is really hard to work with them
     
  20. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice