首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >程序内采购不工作于ios7 /分配给..。从不相容类型

程序内采购不工作于ios7 /分配给..。从不相容类型
EN

Stack Overflow用户
提问于 2014-03-02 12:42:33
回答 1查看 489关注 0票数 0

我跟踪了本教程,它似乎在ios6中运行得很好,但是当我尝试使用ios7时,它从不调用:

代码语言:javascript
复制
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)

(修复了不兼容的类型错误,多亏了Macro206) (应用程序中的采购仍然不能在ios7上工作(但在ios6(能够购买,广告横幅的alpha设置为0(当BOOL为真时,从我的应用程序中设置))工作得很好)

以下是我所拥有的:(我删除了动画/图形代码,以使其更短)

代码语言:javascript
复制
//
//  MainMenu.m
//  HungryFish
//
//
//
//#import "AppDelegate.h"
#import "MainMenu.h"
#import "cocos2d.h"
#import "HelloWorldLayer.h"
#import "SimpleAudioEngine.h"
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#import <StoreKit/StoreKit.h>
@implementation MainMenu

 CCDirectorIOS *director_;
 BOOL areAdsRemoved=nil;



+(id) scene
{
    CCScene *scene = [CCScene node];

    MainMenu *layer = [MainMenu node];

    [scene addChild: layer];

    return scene;
}
- (BOOL)prefersStatusBarHidden {
    return YES;
}
int ADSIZE;
-(id) init
{

    if( (self=[super init] )) {
        if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
            // iOS 7
            [self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
        } else {
            // iOS 6
            [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
        }




        areAdsRemoved = [[NSUserDefaults standardUserDefaults] boolForKey:@"areAddsRemoved"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        //this will load wether or not they bought the in-app purchase

        if(areAdsRemoved){
            NSLog(@"Ads removed");
           // [self.view setBackgroundColor:[UIColor blueColor]];
            //if they did buy it, set the background to blue, if your using the code above to set the background to blue, if your removing ads, your going to have to make your own code here
        }

    }
    return self;
}



// IN APP PURCHASES


#define kRemoveAdsProductIdentifier @"FishyFishinAPPid"

- (void)tapsRemoveAds{
    NSLog(@"User requests to remove ads");

    if([SKPaymentQueue canMakePayments]){
        NSLog(@"User can make payments");

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kRemoveAdsProductIdentifier]];
        productsRequest.delegate = self;
        [productsRequest start];

    }
    else{
        NSLog(@"User cannot make payments due to parental controls");
        //this is called the user cannot make payments, most likely due to parental controls
    }
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if(count > 0){
        validProduct = [response.products objectAtIndex:0];
        NSLog(@"Products Available!");
        [self purchase:validProduct];
    }
    else if(!validProduct){
        NSLog(@"No products available");
        //this is called if your product id is not valid, this shouldn't be called unless that happens.
    }
}

- (IBAction)purchase:(SKProduct *)product{
    SKPayment *payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:(id)self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (IBAction) restore{
    //this is called when the user restores purchases, you should hook this up to a button
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    NSLog(@"received restored transactions: %i", queue.transactions.count);
    for (SKPaymentTransaction *transaction in queue.transactions)
    {
        if(SKPaymentTransactionStateRestored){
            NSLog(@"Transaction state -> Restored");
            //called when the user successfully restores a purchase
            [self doRemoveAds];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        }

    }

}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    for(SKPaymentTransaction *transaction in transactions){
        switch (transaction.transactionState){
            case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");
                //called when the user is in the process of purchasing, do not add any of your own code here.
                break;
            case SKPaymentTransactionStatePurchased:
                //this is called when the user has successfully purchased the package (Cha-Ching!)
                [self doRemoveAds]; //you can add your code for what you want to happen when the user buys the purchase here, for this tutorial we use removing ads
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"Transaction state -> Purchased");
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"Transaction state -> Restored");
                //add the same code as you did from SKPaymentTransactionStatePurchased here
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                //called when the transaction does not finnish
                if(transaction.error.code != SKErrorPaymentCancelled){
                    NSLog(@"Transaction state -> Cancelled");
                    //the user cancelled the payment ;(
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
        }
    }
}




- (void)doRemoveAds{
    areAdsRemoved = YES;
    [[NSUserDefaults standardUserDefaults] setBool:areAdsRemoved forKey:@"areAdsRemoved"];
    //use NSUserDefaults so that you can load wether or not they bought it
    [[NSUserDefaults standardUserDefaults] synchronize];
}
  // IN APP PURCHASES END
 - (void) dealloc
{
    [super dealloc];
}
@end



//
//  MainMenu.h
//  HungryFish
//
//
//

#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import <StoreKit/StoreKit.h>
@interface MainMenu : CCLayer <SKProductsRequestDelegate>
{
}
extern BOOL areAdsRemoved;
- (IBAction)purchase;
- (IBAction)restore;
- (IBAction)tapsRemoveAdsButton;
+(id) scene;
@end

我收到的警告是:

代码语言:javascript
复制
(At line: @implementation MainMenu)
Method definition for 'tapsRemoveAdsButton' not found
Method definition for 'purchase' not found

我看过类似的问题,但从未真正理解如何修复它,添加了"(id)self“而不是仅仅"self”- -消除了错误,但它没有解决问题,代码在"productsRequest start;“和”- (void)productsRequest:“从不被解雇时停止。

我确信我做的是基本错误=

(哦,万一有关系,我一直在模拟器上测试它,在ios6上工作得很好,在ios7上就不行了)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-02 21:21:31

正如Macro206提到的,您必须在@接口和#import <StoreKit/StoreKit.h>之后添加<SKProductsRequestDelegate>。此外,在应用程序购买应该在一个真正的设备上测试一个特殊的测试帐户.

您的代码被格式化得很糟糕,并且保留了过时的行。如果你想让人们检查你的代码,你应该让他们更容易读懂。看看此链接

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22127674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档