bizz84 / SwiftyStoreKit

Lightweight In App Purchases Swift framework for iOS 8.0+, tvOS 9.0+ and macOS 10.10+ ⛺
MIT License
6.58k stars 795 forks source link

macOS - Validate receipt after immediately app launches #294

Open rebeloper opened 7 years ago

rebeloper commented 7 years ago

Platform

In app purchase type

Environment

Version

0.11.0

Related issues

ℹ Please replace this with references to similar issues (either open or already closed).

Report

Issue summary

Apple wants that the app should validate receipt after immediately app launches.

What did you expect to happen

Apple Review Team Approve my submission.

What happened instead

The Apple Review Team Rejected my app with the following response:

The app should validate receipt after immediately app launches:

Any help on this is appreciated. Thank you.

bizz84 commented 7 years ago

@rebeloper Perhaps you could try to call the fetchReceipt or verifyReceipt methods when the app starts?

msamoylov commented 7 years ago

Hey @rebeloper, any updates? I'm experiencing the same issue with my rejected app.

rebeloper commented 7 years ago

It looks like we need to validate purchases in Main. Now in objective c projects there is a Main.h file but I cannot reach the SwiftyStoreKit module. And in swift projects there is no Main file at all. Still looking for solutions...

msamoylov commented 7 years ago

Nailed it!

macOS applications should perform receipt validation immediately after launch. The apps should call exit with a status of 173 if validation fails as shown in Listing 1.

func applicationDidFinishLaunching(_ aNotification: Notification) {
    // Test whether the app's receipt exists.
    if let url = Bundle.main.appStoreReceiptURL, let _ = try? Data(contentsOf: url) {
        // The receipt exists. Do something.
    } else {
        // Validation fails. The receipt does not exist.
        exit(173)
    }
}

https://developer.apple.com/library/content/technotes/tn2259/_index.html

rebeloper commented 7 years ago

Source: https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html

rebeloper commented 7 years ago

Is the applicationDidFinishLaunchig function the place to call this? Apple docs say:

Perform receipt validation immediately after your app is launched, before displaying any user interface or spawning any child processes. Implement this check in the main function, before the NSApplicationMain function is called.

If so, than we could simply call verifyReceipt if it exists.

msamoylov commented 7 years ago

Yessir. Just used their code snippet and everything worked like a charm.

rebeloper commented 7 years ago

Thumds up @msamoylov This is my first macOS app after hundreds of iOS ones. Will submit my app soon and confirm this solution myself if the app gets approved.