2012-07-10 73 views
1

我在appstore上有一個應用程序,我想添加它在應用程序內購買,一個基本的購買,以購買更多的水平。應用內購買方法(mkstorekit?)

我知道apple sdk很難實現, 我知道mkstorekit是一個容易的,但我無法找到從頭開始使用它的指南。

最好的方法是什麼,以及其他方法?任何好的教程?

非常感謝。

回答

0

首先你需要初始化MKStoreKit。樣本initializiation代碼,您可以添加到您的application:didFinishLaunchingWithOptions:低於在Objective-C

[[MKStoreKit sharedKit] startProductRequest]; 

    [[NSNotificationCenter defaultCenter] addObserverForName:kMKStoreKitProductsAvailableNotification 
                object:nil 
                queue:[[NSOperationQueue alloc] init] 
               usingBlock:^(NSNotification *note) { 

    NSLog(@"Products available: %@", [[MKStoreKit sharedKit] availableProducts]); 
    }]; 


    [[NSNotificationCenter defaultCenter] addObserverForName:kMKStoreKitProductPurchasedNotification 
                object:nil 
                queue:[[NSOperationQueue alloc] init] 
               usingBlock:^(NSNotification *note) { 

                NSLog(@"Purchased/Subscribed to product with id: %@", [note object]); 
               }]; 

    [[NSNotificationCenter defaultCenter] addObserverForName:kMKStoreKitRestoredPurchasesNotification 
                object:nil 
                queue:[[NSOperationQueue alloc] init] 
               usingBlock:^(NSNotification *note) { 

                NSLog(@"Restored Purchases"); 
               }]; 

    [[NSNotificationCenter defaultCenter] addObserverForName:kMKStoreKitRestoringPurchasesFailedNotification 
                object:nil 
                queue:[[NSOperationQueue alloc] init] 
               usingBlock:^(NSNotification *note) { 

                NSLog(@"Failed restoring purchases with error: %@", [note object]); 
               }]; 

您可以檢查是否有產品使用-isProductPurchased如下以前購買的。

if([MKStoreManager isProductPurchased:productIdentifier]) { 
//unlock it 
} 

您可以檢查使用-expiryDateForProduct產品的到期日,如下圖所示。

if([MKStoreManager expiryDateForProduct:productIdentifier]) { 
//unlock it 
} 

要購買一個功能或訂閱自動更新的訂閱,只需撥打

[[MKStoreKit sharedKit] initiatePaymentRequestForProductWithIdentifier:productIdentifier]; 

您還可以找到mkstorekit herehere.

的教程