4

I want to read the original application version from the app's receipt.

In development the app contains no receipt since it's not installed from the store. I need to start a SKReceiptRefreshRequest in order to get a sandbox receipt. But that prompts the user to log in.

So here's the question: If the app is downloaded from the Store in production, is it guaranteed to contain a receipt? Because if not I would need to start a refresh request, which prompts the user for their credentials. And I don't want to do that without context.

If it's not available, what are best practices for this case? Incorporate the SKReceiptRefreshRequest into the "restore purchases" routine?

PS: The app is only available on iOS 9+.

Frank Rupprecht
  • 9,191
  • 31
  • 56

1 Answers1

8

Edit

When is iOS app receipt not available? Here's one scenario where the app receipt will be missing. If a user purchases your app from iTunes on a computer (a non-iOS device) and then later syncs that app to their device, there will not be an app receipt.

See this WWDC 2014 video starting at about 48:30


2nd Edit

Another situation where the app receipt will be missing is when a user restores to a new device. App receipts are device specific and will need to be refetched for the new device.


Original Answer

I am in the process of switching an app from paid to freemium so I also need the original application version. I don't know the answer to your "is it guaranteed to be there" question but here is how I decided to handle it.

At startup I look for a previously persisted original application version. If that does not exist yet (this is probably the first launch) I check for the network. If that's fine I check for the app receipt. If it's there I send it to the app store for validation and, if successful, grab the original application version out of the response and persist it. On subsequent launches that persisted value is there so I don't do the receipt validation again. If the app receipt is not present at startup I do not request a receipt refresh. I agree with you, there is no context at this point.

I'm guessing that this will work in all cases where the network is reachable but I do another check at the point of the IAP. Like this...

                                                 ┌────────────┐                                            
                                                 │  Tap Add   │                                            
                                                 └────────────┘                                            
                                                        │                                                  
┌───────────────────────────────────────────────────────┤                                                  
│                                                       │                                                  
│                                                       ▼                                                  
│                                            ┌────────────────────┐                ┌──────────────────────┐
│              ┌──Don't Know─────────────────│ Pre-IAP customer?  │───Yes─────────▶│   Create new thing   │
│              │                             └────────────────────┘                └──────────────────────┘
│              │                                        │                                                  
│              │                                        │                          ┌──────────────────────┐
│              │                                        └──────No─────────────────▶│         IAP          │
│              │                                                                   └──────────────────────┘
│              │                                                                                           
│              ▼                        ┌────────────────────────────────────────┐                         
│  ┌──────────────────────┐             │Maybe: Allow one grace thing. Warn that │                         
│  │  Network Reachable?  │────No──────▶│ the user must connect to the internet  │                         
│  └──────────────────────┘             │      before adding another thing.      │                         
│              │                        └────────────────────────────────────────┘                         
│             Yes                                                                                          
│              │                                                                                           
│              ▼                        ┌────────────────────────────────────────────────────┐             
│  ┌──────────────────────┐             │  Maybe, depending on your requirements: Alert the  │             
│  │   Receipt Present?   │────No──────▶│user that the app receipt is not present and the app│             
│  └──────────────────────┘             │        store may ask for their credentials.        │             
│              │                        └────────────────────────────────────────────────────┘             
│             Yes                                                  │                                       
│              │                                     ┌─────────────┘                                       
│              ▼                                     ▼                                                     
│  ┌──────────────────────┐             ┌────────────────────────┐                                         
│  │        Valid?        │◀────────────│  Refresh the receipt.  │                                         
│  └──────────────────────┘             └────────────────────────┘                                         
│              │                                                                                           
│              └─Yes───┐                                                                                   
│                      ▼                                                                                   
│  ┌───────────────────────────────────────┐                                                               
└──│ Persist original_application_version  │                                                               
   └───────────────────────────────────────┘                      
Murray Sagal
  • 8,454
  • 4
  • 47
  • 48
  • Thanks for the thorough answer. I was just wandering in which case the receipt wouldn't be there and would need to be requested again… By the way, you can also do local receipt validation and/or reading the version number from it, then you don't need to contact iTunes. – Frank Rupprecht Oct 07 '16 at 07:54
  • This answer was more in response to your last question regarding best practices. I'm not suggesting my approach is a best practice. It's just how I handle it. Regarding local validation I evaluated that approach but opted for app store validation. Getting all the required encryption pieces in place for local validation is not-trivial, at least for me, and to complete an IAP I need to talk to the app store anyway. – Murray Sagal Oct 08 '16 at 13:36