应用内购买不工作的ios7 /分配到..从不兼容的类型

问题描述:

我跟着this tutorial,它似乎是工作的罚款为iOS6的,但是当我尝试ios7它永远不会调用:应用内购买不工作的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)自我”,而不只是“自我”摆脱了错误但它不能解决问题,代码停在“[productsRequest start];”和“ - (void)productsRequest:”永远不会被解雇。

我知道我在做基本的错误=(

(哦,在它很重要,我在模拟器上进行了测试它的情况下,适用于iOS6的罚款,但没有对ios7)

+0

看来你的MainMenu类没有声明它符合SKProductsRequestDelegate协议... – Macro206

+1

你在@interface后面添加了吗? – Macro206

+0

我早些时候尝试过,并认为我做错了什么,因为它出现了一个错误。结束我只需#import ,错误消失了。 不幸的是,它仍然没有工作(在ios7上)。没有错误,似乎要解雇的最后一行代码是[productsRequest start];那么它永远不会达到这种方法。我可以点击它一千次,我在我的控制台中看到的是:“用户请求删除广告”“用户可以付款”,然后什么也不是。 – JMC17

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

你的代码是非常格式化,您把过时的线如果你想要人们检查你的代码,你应该让它们变得更容易并重新使用它adable。看看this link

+0

据我所知,它应该在真实的设备上测试,但它的ios6与模拟器很好地工作,为什么不会为ios7?模拟器允许我在我不拥有的设备上进行测试。我很抱歉我的代码的格式,你必须明白这是我遵循的教程。我不确定是否过时的行代表空行或代码不需要。 – JMC17

+1

你是否按照其他建议? – Christian

+0

是的,我使用ios7在真实设备上测试过,效果很好,谢谢。 – JMC17