内购In-App Purchase

转载自:http://blog.csdn.net/gwh111/article/details/19334259

https://developer.apple.com/in-app-purchase/In-App-Purchase-Guidelines.pdf

允许范围:
电子书或者电子相册
额外游戏关数
地图
电子杂志
数字资料

四种种类:
内容
功能
服务
子部件

五种类别:
可消耗
不可消耗
自动更新
免费订阅?
不可更新

对于内容:设置一个binary,enable it 当用户购买后

https://developer.apple.com/in-app-purchase/

invalid product IDs

1.有没有enabled In-App Purchases for your App ID?
2.有没有设置为Cleared for Sale
3.有没有上传过二进制文件(然后rejected it?
4.你的project's .plist BundleID 是否和你的App ID 一致?
5.有没有安装新的provisioning profile?
6. 使用完整的product ID?
7.等待两个小时以上
8.删除旧的应用,重新安装一遍
9. 有没有越狱? (我就是越狱了-。-) 越狱的机子无法测试内购

测试购买失败?

有没有注销你设备上的app store。必须第一次就注销,否则出现什么情况

提示你已经购买了此程序内购买项目,但尚未下载.

解决办法:1.换一台设备?2.等几天

.h

[cpp] view plaincopyprint?
  1. #import <UIKit/UIKit.h>
  2. #import <StoreKit/StoreKit.h>
  3. #define kInAppPurchaseManagerProductsFetchedNotification @"kInAppPurchaseManagerProductsFetchedNotification"
  4. #define kInAppPurchaseManagerTransactionFailedNotification @"kInAppPurchaseManagerTransactionFailedNotification"
  5. #define kInAppPurchaseManagerTransactionSucceededNotification @"kInAppPurchaseManagerTransactionSucceededNotification"
  6. @interface cgViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,SKProductsRequestDelegate,SKPaymentTransactionObserver>{
  7. SKProduct *proUpgradeProduct;
  8. SKProductsRequest *productsRequest;
  9. }
  10. - (void)loadStore;
  11. - (BOOL)canMakePurchases;
  12. - (void)purchaseProUpgrade;
  13. @end

.m

[cpp] view plaincopyprint?
  1. #define kInAppPurchaseProUpgradeProductId @"完整的product id"
  2. #pragma -
  3. #pragma Public methods
  4. //
  5. // call this method once on startup
  6. //
  7. - (void)loadStore
  8. {
  9. // restarts any purchases if they were interrupted last time the app was open
  10. [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
  11. // get the product description (defined in early sections)
  12. [self requestProUpgradeProductData];
  13. }
  14. //
  15. // call this before making a purchase
  16. //
  17. - (BOOL)canMakePurchases
  18. {
  19. NSLog(@"%d",[SKPaymentQueue canMakePayments]);
  20. return [SKPaymentQueue canMakePayments];
  21. }
  22. //
  23. // kick off the upgrade transaction
  24. //
  25. - (void)purchaseProUpgrade
  26. {
  27. NSLog(@"ppp");
  28. SKPayment *payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId];
  29. [[SKPaymentQueue defaultQueue] addPayment:payment];
  30. }
  31. #pragma -
  32. #pragma Purchase helpers
  33. //
  34. // saves a record of the transaction by storing the receipt to disk
  35. //
  36. - (void)recordTransaction:(SKPaymentTransaction *)transaction
  37. {
  38. if ([transaction.payment.productIdentifier isEqualToString:kInAppPurchaseProUpgradeProductId])
  39. {
  40. // save the transaction receipt to disk
  41. [[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
  42. [[NSUserDefaults standardUserDefaults] synchronize];
  43. }
  44. }
  45. //
  46. // enable pro features
  47. //
  48. - (void)provideContent:(NSString *)productId
  49. {
  50. if ([productId isEqualToString:kInAppPurchaseProUpgradeProductId])
  51. {
  52. // enable the pro features
  53. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isProUpgradePurchased" ];
  54. [[NSUserDefaults standardUserDefaults] synchronize];
  55. }
  56. }
  57. //
  58. // removes the transaction from the queue and posts a notification with the transaction result
  59. //
  60. - (void)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:(BOOL)wasSuccessful
  61. {
  62. // remove the transaction from the payment queue.
  63. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  64. NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction, @"transaction" , nil];
  65. if (wasSuccessful)
  66. {
  67. // send out a notification that we’ve finished the transaction
  68. NSLog(@"succ");
  69. [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:userInfo];
  70. }
  71. else
  72. {
  73. // send out a notification for the failed transaction
  74. NSLog(@"fail");
  75. [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo];
  76. }
  77. }
  78. //
  79. // called when the transaction was successful
  80. //
  81. - (void)completeTransaction:(SKPaymentTransaction *)transaction
  82. {
  83. [self recordTransaction:transaction];
  84. [self provideContent:transaction.payment.productIdentifier];
  85. [self finishTransaction:transaction wasSuccessful:YES];
  86. }
  87. //
  88. // called when a transaction has been restored and and successfully completed
  89. //
  90. - (void)restoreTransaction:(SKPaymentTransaction *)transaction
  91. {
  92. [self recordTransaction:transaction.originalTransaction];
  93. [self provideContent:transaction.originalTransaction.payment.productIdentifier];
  94. [self finishTransaction:transaction wasSuccessful:YES];
  95. }
  96. //
  97. // called when a transaction has failed
  98. //
  99. - (void)failedTransaction:(SKPaymentTransaction *)transaction
  100. {
  101. if (transaction.error.code != SKErrorPaymentCancelled)
  102. {
  103. // error!
  104. [self finishTransaction:transaction wasSuccessful:NO];
  105. }
  106. else
  107. {
  108. // this is fine, the user just cancelled, so don’t notify
  109. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
  110. }
  111. }
  112. #pragma mark -
  113. #pragma mark SKPaymentTransactionObserver methods
  114. //
  115. // called when the transaction status is updated
  116. //
  117. - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
  118. {
  119. for (SKPaymentTransaction *transaction in transactions)
  120. {
  121. switch (transaction.transactionState)
  122. {
  123. case SKPaymentTransactionStatePurchased:
  124. [self completeTransaction:transaction];
  125. break;
  126. case SKPaymentTransactionStateFailed:
  127. [self failedTransaction:transaction];
  128. break;
  129. case SKPaymentTransactionStateRestored:
  130. [self restoreTransaction:transaction];
  131. break;
  132. default:
  133. break;
  134. }
  135. }
  136. }
  137. - (void)requestProUpgradeProductData
  138. {
  139. NSSet *productIdentifiers = [NSSet setWithObject:@"gwh.syzg.syzgtext" ];
  140. productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
  141. productsRequest.delegate = self;
  142. [productsRequest start];
  143. // we will release the request object in the delegate callback
  144. }
  145. #pragma mark -
  146. #pragma mark SKProductsRequestDelegate methods
  147. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
  148. {
  149. NSArray *products = response.products;
  150. proUpgradeProduct = [products count] == 1 ? [products firstObject]  : nil;
  151. if (proUpgradeProduct)
  152. {
  153. NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
  154. NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
  155. NSLog(@"Product price: %@" , proUpgradeProduct.price);
  156. NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
  157. }
  158. for (NSString *invalidProductId in response.invalidProductIdentifiers)
  159. {
  160. NSLog(@"Invalid product id: %@" , invalidProductId);
  161. }
  162. // finally release the reqest we alloc/init’ed in requestProUpgradeProductData
  163. [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
  164. }

demo:http://download.csdn.net/detail/gwh111/6932009

Important: To associate In-App Purchase products with the release of your app, make sure its status is “Prepare for Upload.”

https://developer.apple.com/library/ios/documentation/LanguagesUtilities/Conceptual/iTunesConnectInAppPurchase_Guide/Chapters/SubmittingInAppPurchases.html#//apple_ref/doc/uid/TP40013727-CH5-SW1

更多内容参考:

http://www.cocoachina.com/bbs/read.php?tid=69165&keyword=IAP%3C/p%3E

http://www.cocoachina.com/gamedev/misc/2012/0409/4129.html

iOS内购In-App Purchase相关推荐

  1. iOS 内购(In-App Purchase)详解

    iOS 内购(In-App Purchase)详解 概述 IAP 全称:In-App Purchase,是指苹果 App Store 的应用内购买,是苹果为 App 内购买虚拟商品或服务提供的一套交易 ...

  2. iOS内购—— In-App Purchase(消耗型)

    iOS应用如果涉及到支付功能,分为两类:第三方支付和苹果内购.那么什么情况下选择使用第三方支付,又在什么情况下选择苹果内购呢?让我们先来简单了解一下: Understanding What You C ...

  3. iOS 内购项目的App Store推广

    iOS 11以后的用户可以在App Store内的下载页面内直接购买应用的内购商品,这项功能苹果称作做Promoting In-App Purchases,如果你的App需要在App Store推广自 ...

  4. iOS内购-防越狱破解刷单

    ---------------------------2018.10.16更新--------------------------- 最近我们公司丢单率上涨,尤其是10月份比9月份来说丢单率翻了3倍, ...

  5. iOS 内购StoreKit 框架介绍

    StoreKit 框架介绍 一.StoreKit 能做什么? In-App Purchase 提供和促进内容和服务的应用内购买. Apple Music 检查用户的Apple Music功能并提供订阅 ...

  6. Unity接入iOS内购

    1.内购种类 consumable:可消费的,如游戏中的金币,用完还可以再购买. non-consumable:不可销毁的,一次购买,永久生效.比如去广告,解锁游戏关卡,这种商品只能购买一次. sub ...

  7. iOS 内付费(in-app purchase)--非消耗品的购买与恢复

    iOS内付费的功能对于一个app来说是非常重要的,如果在这一环节出了一些致命的问题,那就很可能会影响app的推广和公司的利益了. 我在很早之前写过一篇关于iOS内付费的文章(文章地址),在那篇博客中讲 ...

  8. ios内购二次验证安全性问题_iOS 内购遇到的坑

    一.内购沙盒测试账号在支付成功后,再次购买相同 ID 的物品,会提示如下内容的弹窗.您以购买过此APP内购项目,此项目将免费恢复 您以购买过此APP内购项目,此项目将免费恢复.PNG 原因: 当使用内 ...

  9. iOS内购:自动续期订阅总结

    前言:内购类型有四种:消耗型商品,非消耗型商品,非续期订阅,自动续期订阅. 顾名思义,从中最有难度的就是自动续期订阅的实现,开通自动续期订阅后,订阅会员的处理将会遇到如下问题:自动订阅的到期继续自动订 ...

  10. iOS内购二:购买和恢复

    iOS内购二:购买和恢复 购买 构建一个SKPayment对象,传递SKProduct.SKPayment被创建后,就会将其加入到SKPaymentQueue队列中 然后用户会授权,payment是异 ...

最新文章

  1. nginx 反向代理 apache 服务
  2. Linux(DeepInOS) 下 mysql 的安装与基本配置
  3. 激活层是每一层都有吗_89小户型复式这样装,每一层都设计得很棒,完工后秒变小区样板间,邻居前来取经...
  4. ABP入门系列(5)——展现层实现增删改查
  5. 最全元素水平垂直居中方法
  6. mysql服务突然丢失解决方案
  7. np.argmin和argmax
  8. 使用SDL2中SDL_CreateWindow()函数时报错跳进wincore.cpp(wntdll.pbd not load)
  9. ovnif摄像头修改ip
  10. 如何搭建个人博客网站
  11. css html5布局方式_创建新HTML5 / CSS3单页布局–艺术主题
  12. ‘primordial is not defined‘ node 报错解决方法 终极篇!!
  13. 计算机科技手抄报内容,科技手抄报内容-科技在我身边
  14. 数据禾|全国10米DEM数字高程数据
  15. 硕士毕业论文写不出来导致严重焦虑,怎么办?
  16. xls和 xlsx的区别 xlsx Excel文件怎么转换成 xls文件
  17. TensorRT下FP32转INT8的过程
  18. 【python学习】数据预处理-如何归一化?
  19. SecureCRT8.1破解版下载及修改显示行数
  20. 神经网络与深度学习笔记汇总一

热门文章

  1. C++排序——Bookshelf B
  2. 2018-2019-2 网络对抗技术 20165230 Exp4 恶意代码分析
  3. 服务器如何ghost系统安装,如何在Ubuntu Server 14.04 LTS上安装Ghost
  4. ibm tivoli_了解Tivoli Federated Identity Manager信息服务6.2
  5. ERA5 积雪 降雪 区别_“雪走霾来” 河南降雪今夜停止 19-24日将迎雾霾天
  6. 《我学区块链》—— 八、用区块链投票
  7. html5的交互式微课,交互式微课这样制作更轻松
  8. 项目数据表中的并发控制机制之version
  9. 在OpenCV里实现扑克牌识别1
  10. 利用JBOSS漏洞抓肉鸡