-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.swift
More file actions
54 lines (52 loc) · 2.04 KB
/
main.swift
File metadata and controls
54 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Foundation
// For knowing which field type corresponds to what data,
// please see "Receipt Fields"
// https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html
let data = NSData(contentsOfFile: "./receipt_payload.sample")
if let data = data {
let receipt = AppStoreReceipt(payloadData: data)
receipt.enumerateReceiptAttributes { (type, version, value) in
switch (type) {
case 2: fallthrough
case 3: fallthrough
case 19: fallthrough
case 21:
println("type = \(type); data (\(value.length) bytes) = \(value)")
if let str = AppStoreReceipt.decodeASN1String(value) {
println(" string: \"\(str)\"")
}
println("")
case 4: fallthrough
case 5:
println("type = \(type); data (\(value.length) bytes) = \(value)")
println("")
case 17:
let inAppPurchaseReceipt = AppStoreReceipt(payloadData: value)
inAppPurchaseReceipt.enumerateReceiptAttributes { (type, version, value) in
switch (type) {
case 1702: fallthrough
case 1703: fallthrough
case 1704: fallthrough
case 1705: fallthrough
case 1706: fallthrough
case 1712:
println("type = \(type); data (\(value.length) bytes) = \(value)")
if let str = AppStoreReceipt.decodeASN1String(value) {
println(" string: \"\(str)\"")
}
println("")
case 1701:
println("type = \(type); data (\(value.length) bytes) = \(value)")
if let intVal = AppStoreReceipt.decodeASN1Integer(value) {
println(" integer: [\(intVal)]")
}
println("")
default:
break
}
}
default:
break
}
}
}