SKProductsRequest不返回任何结果

时间:2013-05-23 01:42:07

标签: ios itunesconnect in-app-purchase

我正在尝试在我的应用中使用iap。这些都是以游戏黄金购买,可以使用一次以上。我从noob教程编写代码并且它可以在那里工作项目有人可以告诉我我做错了吗?

#import "IAP.h"
#import "Money.h"

@interface IAP ()

@end

@implementation IAP;




#define kStoredData @"com.AlexApps.TinyTrucks"




+(void)myIAPWithItem:(NSString *)Item{
    if ([SKPaymentQueue canMakePayments]) {
        NSString *PurchaseAddress = [[NSString alloc] initWithString:[NSString stringWithFormat:@"TTE_%@kGold" , Item]];
        //PurchaseAddress is the appId for this in app purchase
        SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PurchaseAddress]];

        request.delegate = self;
        [request start];


    } else {
        UIAlertView *tmp = [[UIAlertView alloc]
                            initWithTitle:@"Prohibited"
                            message:@"Parental Control is enabled, cannot make a purchase!"
                            delegate:self
                            cancelButtonTitle:nil
                            otherButtonTitles:@"Ok", nil];
        [tmp show];

    }



}


#pragma mark StoreKit Delegate

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:{

                // show wait view here

                break;
            }
            case SKPaymentTransactionStatePurchased:{

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                // remove wait view and unlock feature 2

                UIAlertView *tmp = [[UIAlertView alloc]
                                    initWithTitle:@"Complete"
                                    message:@"You have unlocked Feature 2!"
                                    delegate:self
                                    cancelButtonTitle:nil
                                    otherButtonTitles:@"Ok", nil];
                [tmp show];





                // apply purchase action  - hide lock overlay and
                NSLog(@"befvsda");

                // do other thing to enable the features

                break;
            }
            case SKPaymentTransactionStateRestored:{
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                // remove wait view here
                                break;
            }
            case SKPaymentTransactionStateFailed:{

                if (transaction.error.code != SKErrorPaymentCancelled) {
                    NSLog(@"Error payment cancelled");
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                // remove wait view here
                               break;
            }
            default:{
                break;
            }
        }
    }
}

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{

    // remove wait view here


    SKProduct *validProduct = nil;
    int count = [response.products count];

    if (count>0) {
        validProduct = [response.products objectAtIndex:0];

        SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.emirbytes.IAPNoob.01"];
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];


    } else {
        UIAlertView *tmp = [[UIAlertView alloc]
                            initWithTitle:@"Not Available"
                            message:@"No products to purchase"
                            delegate:self
                            cancelButtonTitle:nil
                            otherButtonTitles:@"Ok", nil];
        [tmp show];

    }


}

-(void)requestDidFinish:(SKRequest *)request
{

}

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}



#pragma mark AlertView Delegate

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

程序到达这一行:

SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PurchaseAddress]];
request.delegate = self;
[request start];

然后它就停止了,并且没有从苹果那里得到任何回报。

2 个答案:

答案 0 :(得分:0)

确保您的委托已设置,您有request.delegate = self;,但您在类方法中使用self。我不知道那是怎么回事。

+(void)myIAPWithItem:(NSString *)Item更改为实例方法-(void)myIAPWithItem:(NSString *)Item,然后实例化Money类并调用该方法。看看是否有帮助。

答案 1 :(得分:0)

您确定在com.emirbytes.IAPNoob.01中为产品ID iTunesConnect创建了设置。

如果您已创建,请检查您在com.emirbytes.IAPNoob.01

创建的产品ID iTunesConnect的拼写

更新1:Bundle ID不同,Product ID不同。

Bundle ID是App使用的唯一标识符。 Product ID是用于购买产品列表的唯一标识符。

假设com.emirbytes.IAPNoob是bundleID和

  1. com.emirbytes.IAPNoob.swords - 是购买剑的产品ID
  2. com.emirbytes.IAPNoob.soldiers - 是购买士兵的产品ID
  3. 要创建Product ID,您必须转到iTunesConnect并创建一个应用,并且必须在Manage In-App Purchases中设置产品ID。