gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:14:16 25 4
gpt4 key购买 nike

我关注了this tutorial它似乎适用于 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”消除了错误,但它没有解决问题,代码停在“[产品请求开始];"和“- (void)productsRequest:”永远不会被解雇。

我确定我犯了基本错误 =(

(哦,以防万一,我一直在模拟器中测试它,在 ios6 上运行良好但在 ios7 上运行不正常)

最佳答案

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

您的代码格式非常糟糕,并且保留了过时的代码行。如果你想让人们审查你的代码,你应该让他们更容易阅读。看看this link

关于ios - 应用内购买不适用于 ios7/从不兼容的类型分配给..,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com