1

アプリで 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];

その後、停止し、アップルから何も返されません。

4

2 に答える 2

0

で製品 ID の設定を作成しましたかcom.emirbytes.IAPNoob.01?iTunesConnect

com.emirbytes.IAPNoob.01作成されている場合は、作成したproductID のスペルを確認してくださいiTunesConnect

更新 1:いいえBundle IDProduct ID違います。違います。

Bundle IDアプリに使用される一意の識別子です。Product ID製品リストの購入に使用される一意の識別子です。

com.emirbytes.IAPNoobbundleID としましょう

  1. com.emirbytes.IAPNoob.swords - 剣を購入するためのプロダクト ID
  2. com.emirbytes.IAPNoob.soldiers- 兵士を購入するためのプロダクト ID

を作成するProduct IDには、iTunesConnectに移動して1 つのアプリを作成し、でプロダクト ID を設定する必要がありますManage In-App Purchases

于 2013-05-24T04:06:37.543 に答える
0

デリゲートが設定されていることを確認してください。ただし、クラスメソッドでrequest.delegate = self;使用しています。selfそれがどのように機能しているのかわかりません。

+(void)myIAPWithItem:(NSString *)Itemインスタンス メソッドに変更してから-(void)myIAPWithItem:(NSString *)Item、Money クラスをインスタンス化し、メソッドを呼び出します。それが役立つかどうかを確認してください。

于 2013-05-23T02:11:59.783 に答える