01. 1 #pragma mark -
02. 2 #pragma mark - SKPaymentTransactionObserver Methods
03. 3 // 产品购买过程中到状态
04. 4 - ( void )paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
05. 5 {
06. 6 for (SKPaymentTransaction *transaction in transactions) {
07. 7 switch (transaction.transactionState) {
08. 8 case SKPaymentTransactionStatePurchased:
09. 9 [self completeTransaction:transaction];
10. 10 break ;
11. 11 case SKPaymentTransactionStateFailed:
12. 12 [self failedTransaction:transaction];
13. 13 break ;
14. 14 case SKPaymentTransactionStateRestored:
15. 15 [self restoreTransaction:transaction];
16. 16
17. 17 default :
18. 18 break ;
19. 19 }
20. 20 }
21. 21 }
22. 22
23. 23 // 购买完成的处理
24. 24 - ( void )completeTransaction:(SKPaymentTransaction *)transaction
25. 25 {
26. 26 // 通知u3d购买成功,返回product ID
27. 27 UnitySendMessage( "Interface" , "purchaseSuccessful" ,[[NSString stringWithFormat:@ "%@,%@" ,transaction.payment.productIdentifier,transaction.transactionIdentifier] UTF8String]);
28. 28 [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
29. 29 }
30. 30
31. 31 // 购买失败的处理
32. 32 - ( void )failedTransaction:(SKPaymentTransaction *)transaction
33. 33 {
34. 34 // 通知u3d购买失败
35. 35 // 错误信息为transaction.error.code
36. 36 // SKErrorUnknown,
37. 37 // SKErrorClientInvalid, // client is not allowed to issue the request, etc.
38. 38 // SKErrorPaymentCancelled, // user cancelled the request, etc.
39. 39 // SKErrorPaymentInvalid, // purchase identifier was invalid, etc.
40. 40 // SKErrorPaymentNotAllowed, // this device is not allowed to make the payment
41. 41 // SKErrorStoreProductNotAvailable, // Product is not available in the current storefront
42. 42
43. 43 UnitySendMessage( "Interface" , "purchaseFailed" , [[NSString stringWithFormat:@ "%d" ,transaction.error.code] UTF8String]);
44. 44 [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
45. 45 }
46. 46
47. 47 // 购买到永久有效物品的处理
48. 48 - ( void )restoreTransaction:(SKPaymentTransaction *)transaction
49. 49 {
50. 50 // 通知u3d购买成功
51. 51 UnitySendMessage( "Interface" , "purchaseSuccessful" ,[[NSString stringWithFormat:@ "%@,%@" ,transaction.payment.productIdentifier,transaction.transactionIdentifier] UTF8String]);
52. 52 [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
53. 53 }
|