Last active
August 29, 2015 14:06
-
-
Save hartlco/544e2a37cca7c7795926 to your computer and use it in GitHub Desktop.
Obtaining the Appstore receipt for iOS Apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppStoreReceiptObtainer: NSObject, SKRequestDelegate { | |
let receiptUrl = NSBundle.mainBundle().appStoreReceiptURL | |
func obtainReceipt() { | |
var fileExists = NSFileManager.defaultManager().fileExistsAtPath(receiptUrl.path!) | |
if fileExists { | |
println("Appstore Receipt already exists") | |
return; | |
} | |
requestReceipt() | |
} | |
func requestReceipt() { | |
println("request a receipt") | |
let request = SKReceiptRefreshRequest(receiptProperties: nil) | |
request.delegate = self | |
request.start() | |
} | |
//MARK: SKRequestDelegate methods | |
func requestDidFinish(request: SKRequest!) { | |
println("request did finish") | |
var fileExists = NSFileManager.defaultManager().fileExistsAtPath(receiptUrl.path!) | |
if fileExists { | |
println("Appstore Receipt now exists") | |
return | |
} | |
println("something went wrong while obtaining the receipt, maybe the user did not successfully enter it's credentials") | |
} | |
func request(request: SKRequest!, didFailWithError error: NSError!) { | |
println("request did fail with error: \(error.domain)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment