成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

IAP最佳實踐方法

移動開發 iOS
該文檔是蘋果8月5號發布的新Technical Note,最要描述了iOS 和 OS X 應用程序中的IAP的最佳實踐。 以下是推薦給開發者的IAP最佳實踐列表。

[[118315]]

該文檔是蘋果8月5號發布的新Technical Note--In-App Purchase Best Practices,最要描述了iOS 和 OS X 應用程序中的IAP的最佳實踐。

以下是推薦給開發者的IAP最佳實踐列表。

在應用啟動時添加一個交易隊列觀察者

應用程序調用StoreKit把觀察者鏈接到payment queue。

  1. [SKPaymentQueue defaultQueue] addTransactionObserver:your_observer];  

在恢復或者運行你的app應用時,如果支付隊列的內容發生了變化,StoreKit則會自動通知你(注冊的)觀察者 在應用啟動時添加觀察者確保它在所有app啟動時都會存在,這將允許你的應用能接收到所有的payment queue提醒。

考慮應用程序這樣一個情況,在向隊列(如表1)添加支付請求前,應用的 DetailViewController 類創建了一個觀察者。這個觀察者的存在時間和 DetailViewController 實例一樣長。如果出現中斷情況,比如網絡失敗,那么app將不能完成購買流程,而相關的交易仍在支付隊列中。當app正常恢復后,它將沒有觀察者存在,因 為在應用被發送至后臺時,上述觀察者就已經被解除了。因此,你的應用將不會收到隊列中的交易通知。

列表 1.不遵循實現交易觀察者最佳實踐:當用戶嘗試購買產品時,應用為 payment queue 添加觀察者:

  1. @implementation DetailViewController  
  2.                   ....  
  3.    
  4. // Called when a customer attempts to purchase a product  
  5. - (IBAction)purchase:(id)sender  
  6. {  
  7.     // Register an observer to the payment queue  
  8.     [[SKPaymentQueue defaultQueue] addTransactionObserver:self];  
  9.    
  10.     // Create a payment request  
  11.     SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:self.product];  
  12.    
  13.     // Submit the payment request to the payment queue  
  14.     [[SKPaymentQueue defaultQueue] addPayment:payment];  
  15. }  
  16.              ....  
  17. @end  

列表 2.遵循注冊交易觀察者的最佳實踐

  1. @implementation AppDelegate  
  2.    
  3. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  4. {  
  5.     // Attach an observer to the payment queue  
  6.     [[SKPaymentQueue defaultQueue] addTransactionObserver:self];  
  7.     return YES;  
  8. }  
  9.    
  10. // Called when the application is about to terminate  
  11. - (void)applicationWillTerminate:(UIApplication *)application  
  12. {  
  13.      // Remove the observer  
  14.     [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];  
  15. }  
  16.    
  17.             ....  
  18. @end  

StoreKit 在app調用時從payment queue移除觀察者: 

同樣,如果沒有從 payment queue 移除觀察者,StoreKit 將會試圖通知上述觀察者,從而導致應用崩潰,好像觀察者已經不復存在了。

在展示應用內商店UI之前向App Store詢問產品信息

在決定在用戶界面中展示可購買商品之前,你的應用必須首先向App Store發送一個產品請求。發送產品請求可讓你確定產品是否可在App Store中出售,從而阻止展示不能購買的產品。可查看 Retrieving Product Information 學習如何創建一個產品請求。App Store使用 SKResponse 對象響應產品請求,使用其 products 屬性來更新你的UI,以確保你的用戶只能看到App Store中可供銷售的產品。

列表 3.不遵循IAP產品展示最佳實踐:在展示可銷售產品后, APP向App Store詢問相關產品信息。

  1. // App first displays a product for sale, then queries the App Store about it when a customer attempts to purchase it  
  2. - (IBAction)purchase:(id)sender  
  3. {  
  4.     // Create a set for your product identifier  
  5.     NSSet *productSet = [NSSet setWithObject:@"your_product_identifier"];  
  6.     // Create a product request object and initialize it with the above set  
  7.     SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:productSet];  
  8.    
  9.     request.delegate = self;  
  10.     // Send the request to the App Store  
  11.     [request start];  
  12. }  
  13.    
  14.    
  15.    
  16. // Get the App Store's response  
  17. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response  
  18. {  
  19.    // No purchase will take place if there are no products available for sale.  
  20.   // As a result, StoreKit won't prompt your customer to authenticate their purchase.  
  21.    if ([response.products count] > 0)  
  22.    {  
  23.         SKProduct *product = (SKProduct *)[response.products objectAtIndex:0];  
  24.    
  25.         // The product is available, let's submit a payment request to the queue  
  26.         SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];  
  27.         [[SKPaymentQueue defaultQueue] addPayment:payment];  
  28.     }  
  29. }  

列表 4.  遵循IAP產品展示最佳實踐

  1. -(void)fetchProductInformationForIds:(NSArray *)productIds  
  2. {  
  3.     // Create a set for your product identifier  
  4.     NSSet *mySet = [NSSet setWithObject:your_product_identifier];  
  5.    
  6.     // Create a product request object and initialize it with the above set  
  7.     SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:mySet];  
  8.    
  9.     request.delegate = self;  
  10.    
  11.     // Send the request to the App Store  
  12.     [request start];  
  13. }  
  14.    
  15.    
  16. //Get the App Store's response  
  17. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response  
  18. {  
  19.     if ([response.products count] > 0)  
  20.     {  
  21.         // Use availableProducts to populate your UI  
  22.         NSArray *availableProducts = response.products;  
  23.     }  
  24. }  

為restoring products提供一個UI
如果你的應用出售 non-consumable、auto-renewable subscription 或者 non-renewing subscription產品,那你必須提供一個允許恢復它們的UI。可以查看 Differences Between Product Types 和 Restoring Purchased Products 獲得更多信息。
處理交易
調用 StoreKit 為 payment queue 添加支付請求:

  1. [[SKPaymentQueue defaultQueue] addPayment:your_payment];  

隊列創建交易對象來處理這個請求。當交易狀態改變時,StoreKit通過調用 paymentQueue: updatedTransactions: 來通知你的觀察者。

In-App Purchase Programming Guide> Delivering Products> Table 4-1 Transaction statuses and corresponding actions 列出了每個交易可能存在的4種交易狀態。要確保觀察者的 paymentQueue: updatedTransactions: 可以在任何時間響應這些狀態。如果IAP產品是由蘋果托管的,那么需在在觀察者上實現 paymentQueue:updatedDownloads: 方法。

提供付費內容

當收到一個狀態是 SKPaymentTransactionStatePurchased 或者 SKPaymentTransactionStateRestored 的交易時,應用程序將會向用戶交付內容或者解鎖app的功能。這些狀態表明已經接收到可售產品的付款。用戶也希望應用能提供付費內容。

如果你的購買產品包括App Store托管內容,要確保調用 SKPaymentQueue's startDownloads: 下載內容。可查看 Unlocking App FunctionalityDelivering Associated Content 獲得更多信息。

完成交付

交易將會保存在支付隊列中直到它們被移除。每次啟動應用或者從后臺恢復時,StoreKit將會調用觀察者的 paymentQueue: updatedTransactions: 直到它們被移除。大意是你的用戶可能反復請求驗證它們的購買,或者被阻止購買你的產品。

調用 finishTransaction: 從隊列中移除交易。完成的交易是不可恢復的,因此你務必提供內容,下載所有蘋果托管的產品內容,或者在完成交易前完成你的購買流程。查看 Finishing the Transaction 獲得更多信息。

測試IAP的實現

要確保在把應用提交審核之前徹底測試IAP的實現。可在 Suggested Testing Steps 查看多測試場景,在 Frequently Asked Questions 查看各種疑難解答。

參考:

 

In-App Purchase Programming Guide

Adding In-App Purchase to your iOS and OS X Applications

WWDC 2012: Selling Products with Store Kit

WWDC 2012: Managing Subscriptions with In-App Purchase

WWDC 2013: Using Store Kit for In-App Purchases

WWDC 2014: Optimizing In-App Purchases

本文鏈接:http://www.cocoachina.com/applenews/devnews/2014/0818/9407.html

 

責任編輯:chenqingxiang 來源: cocoachina
相關推薦

2011-09-01 14:36:38

敏捷

2024-05-16 13:13:39

微服務架構自動化

2022-06-28 13:25:19

K8sPrometheusGrafana

2011-08-18 11:05:21

jQuery

2023-07-21 01:12:30

Reactfalse?變量

2013-07-24 10:03:15

2013-08-12 09:45:06

最佳編程方法編程方法編程

2012-08-09 09:10:56

代碼審查代碼

2014-06-09 15:50:08

2024-08-21 08:02:47

2011-12-21 13:35:39

JavaJFreeChart

2015-09-23 09:08:38

java反射

2011-12-21 13:52:27

JavaJFreeChart

2023-09-11 08:50:03

Maven工具關系管理

2010-12-02 08:12:16

2023-09-13 08:00:00

JavaScript循環語句

2010-07-06 09:07:09

2011-12-21 13:44:33

JavaJFreeChart

2023-05-15 08:24:46

2013-06-13 09:21:31

RESTful APIRESTfulAPI
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲综合日韩精品欧美综合区 | 曰批视频在线观看 | 国产精品久久久亚洲 | 亚洲国产精品一区二区久久 | 久久精品久久综合 | 涩涩视频网站在线观看 | 亚洲欧美精品久久 | 三级在线观看 | 中文字幕av在线 | 久久精品99 | 久久99一区二区 | 国产九九av | 五月综合色啪 | 日韩福利在线观看 | 国产精品视频一二三区 | 久草高清视频 | 亚洲高清视频一区二区 | 91久久伊人 | 亚洲午夜av久久乱码 | 国产极品91 | 久久91av| 不卡av在线| 91一区二区三区在线观看 | 成人国产综合 | av免费网址 | 男女污污动态图 | 日韩精品一区二区三区高清免费 | 91久久精品 | 成人深夜福利在线观看 | 天天综合网91 | av日韩在线播放 | 国产在线一区二区三区 | 久久久久国产一区二区三区 | 免费高潮视频95在线观看网站 | 日本精品久久久一区二区三区 | 亚洲欧美日韩在线一区二区 | 精品欧美一区二区三区免费观看 | 日韩在线综合网 | 欧美性生活一区二区三区 | 免费欧美 | 日韩免费福利视频 |