应用内购买不适用于ios7 /从不兼容类型分配给..

JMC17

我遵循了本教程,它对于ios6似乎运行良好,但是当我尝试使用ios7时,它永远不会调用:

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

(修复了不兼容的类型错误,这要归功于Macro206)(在ios7上仍无法使用应用内购买功能(但在ios6上似乎可以正常使用(可以购买并且广告横幅的Alpha设置为0(在BOOL上设置了Alpha设置))是真实的,来自我应用程序的其他位置))))

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

//
//  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

我得到的警告是:

(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上不能正常工作)

基督教

就像提到的Macro206一样,您必须<SKProductsRequestDelegate>在@interface AND之后添加#import <StoreKit/StoreKit.h>此外,应在具有特殊测试帐户的真实设备上对应用内购买进行测试。

您的代码格式非常糟糕,并且您已经过时了。如果您希望人们查看您的代码,则应该使他们更容易阅读并使其易于阅读。看看这个链接

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

iOS SKSpriteNode错误:从不兼容的类型“ CGRect”(也称为“ struct CGRect”)分配给“ skspritenode * const __strong”

应用内购买不适用于iOS7

如何禁用从不兼容类型警告分配给..?

从不兼容类型'id <UIApplicationDelegate>'分配给'AppDelegate *'

错误:从不兼容类型void *分配给char *

从不兼容类型'int(^ __ strong)(void)'分配给'int'

指针问题:从不兼容的类型“int”分配给“int *”

编译错误:尝试将数组分配给数组时,从不兼容的类型“char”分配给“int”

从不兼容类型'ViewController * const_strong'分配给'id <Delegate>'

从不兼容的类型'ViewController * const__strong'分配给'id <UINavigationControllerDelegate,UIImagePickerControllerDelegate>'

C ++错误:从不兼容类型'const char *'分配给'char *'

分配给指针时从不兼容的指针类型警告进行初始化

从不兼容的类型'AppDelegate * const __strong'分配给'NSObject <PushNotificationDelegate> *'

分配给奇数和偶数的对象值但不适用于 `if` 语句

重新打开时分配给该错误的解决方案不适用于mantisbt

警告:在将功能地址分配给功能指针时,从不兼容的指针类型进行分配[默认启用]

类型...不能分配给'从不'类型。(2322)

类型“ any []”不可分配给类型“从不”

类型“数字”不可分配给类型“从不”

从不兼容类型'void(^ __ strong)(int,const char *,int)'分配给'void(*)(int,const char *,int)'

应用内购买不适用于Chrome扩展程序

错误TS2322:类型“对象”不能分配给类型“电影”吗?角度7

类型 X 的参数不能分配给 Angular 7 中类型 X 错误的参数

输入'string | 数字”不能分配给“从不”类型

分配给类型'char [100]'时不兼容的类型

Range.Value 不适用于将单元格内容分配给 VBA 中的变量

ios7 Storybaoard UITableViewCell不适用于表

CGImageCreateWithMaskingColors不适用于iOS7

不兼容的指针类型从'NSMutableArray *'分配给'NSString *'