16

So I have an app which requires a subscription (via an IAP), and it provides a Today Widget. Within the widget (as well as within the app) I use RMStore to check the App Receipt in the bundle for an active subscription. It works fine in the sandbox, including when installed via TestFlight. But today, the app was approved by Apple, and as soon as I tested the live-in-the-store version, while the main app saw the user's purchases in the app receipt, the Today Extension wasn't reading the app receipt, and thus found no subscription!

Both the Today Extension and the main app are using the exact same code to read the app receipt and look for subscription information. Why on earth would it work in the main app but not the extension? Is this a known issue? Is it something to do with RMStore rather than StoreKit itself? Is there something clever/different I have to do?

I'm thinking maybe the issue has to do with the receipt verification -- would something like the bundle identifier be different in the sandbox vs the App Store for the extension, for example?

This is really frustrating, as there's literally no way for me to test any potential solution without resubmitting to the App Store, then testing it once it's released, and pulling it from the store if it's broken, as otherwise I'll have users paying for something they don't actually get.

DanM
  • 7,037
  • 11
  • 51
  • 86
  • 2
    It may be a good idea to post the code you use for reading the app receipt. Not everyone may be familiar with RMStore. – user1459524 May 24 '15 at 14:26
  • 1
    I wouldn't be surprised if it's some issue with entitlements here. IIRC, the app extensions are code signed with different identifiers than the parent and have separate app IDs and all that. Have you confirmed that an extension can actually read the SK receipt? Beyond that, I'm not sure what the workaround is, but if you can verify it in your app, then it sounds like the problem. I've really only seen user defaults with app groups described by Apple as the way to do app-extension communication so this would really suck if SK is indeed unavailable in the extension. – mszaro May 26 '15 at 21:11
  • 1
    I could find zero documentation about extensions reading app receipts, but since it worked fine in the TestFlight-deployed version of the binary I (wrongly?) figured it was fine. – DanM May 26 '15 at 22:32

1 Answers1

11

All receipts (app purchase and in-app purchase/s) are stored in a file inside the application bundle. The app extension resides in a bundle that's nested inside the application bundle - so I would be surprised if it has access to the receipt file in the outer bundle (but worth checking by calling appStoreReceiptURL).

So information about the receipt (i.e. either the receipt itself, or some result of processing the receipt) needs to be passed from the containing app to the extension through the usual means, i.e. using a shared container and maybe file coordination.

roop
  • 1,291
  • 8
  • 10
  • Any thoughts on why it might work in sandbox mode / via TestFlight, but not the App Store? – DanM May 29 '15 at 01:23
  • In TestFlight, all in-app purchases are supposed to be free anyway. What do you mean by "sandbox mode"? Do you mean the normal testing by running the app on a developer device? Did you try that using test App Store accounts? ([This objc.io article](http://www.objc.io/issue-17/receipt-validation.html) has a good overview.) – roop May 29 '15 at 02:02
  • I mean "Sandbox Mode" as referenced here: https://developer.apple.com/library/ios/technotes/tn2259/_index.html ...i.e. purchasing using a test user. This works whether I've deployed via building directly to the device with XCode, or via TestFlight. – DanM May 29 '15 at 19:41
  • So you are using test App Store accounts (thanks, I just learnt that Apple calls this the "Sandbox environment"). I don't know why it works there. Can you check if you can call [`appStoreReceiptURL`](https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW2) (> iOS 7 only) in Sandbox Env and seeing if you can read the file in the returned URL? – roop May 31 '15 at 06:30
  • Yes, in the sandbox environment I can definitely read the appStoreReceiptURL and the file it points to from the Today extension. – DanM May 31 '15 at 11:42
  • I'm not positive, but it does seem like this is the root of the issue, and for some reason it's only a problem in the live app store version. Very odd. Anyway, marking the answer correct. – DanM Jun 02 '15 at 15:50