繁体   English   中英

Xcode 5中的错误“使用未声明的标识符”

[英]Errors in Xcode 5 “use of undeclared identifier”

我的Xcode项目中存在以下错误,无法弄清楚如何纠正它。 我试图保存并关闭Xcode并重新打开该项目,但这不起作用。 我收到以下消息:

通过以下代码使用未声明的标识符“ gremoveads”。

}
if (buttonIndex==2) {
    bool bPaymentInQueue = NO;
    for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
        if ([transaction.payment.productIdentifier isEqualToString:gRemoveads]) {
            bPaymentInQueue = YES;
            NSLog(@"Payment already in queue!");
            break;
        }

我也收到此错误。 将未声明的标识符“ gunlimitedcoins”与以下代码一起使用。

if (buttonIndex==0) {
    bool bPaymentInQueue = NO;
    for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
        if ([transaction.payment.productIdentifier isEqualToString:gUnlimitedCoins]) {
            bPaymentInQueue = YES;
            NSLog(@"Payment already in queue!");
            break;

如何解决这两个未声明的标识符错误?

显示这些错误的完整代码在gamestoreviewcontroller.m文件中。

#import "GameStoreViewController.h"
#import "Reachability.h"
#import "SurfSlotMachineAppDelegate.h"

@implementation GameStoreViewController
@synthesize activityIndicatorView;
@synthesize lblLoading;
@synthesize lblProductTitle;
@synthesize txtProductDescription;
@synthesize txtGamecenterDescription;
@synthesize txtRestoreDescription;
@synthesize txtMoreGamesDescription;
@synthesize btnBuyProduct;
@synthesize btnGameCenter;
@synthesize btnRestore;
@synthesize btnReturn;
@synthesize btnMoreGame;
@synthesize activityIndicatorPurchasingView;
@synthesize lblPurchasing;
@synthesize unlockInfoImage;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
 // Custom initialization
 }
 return self;
 }
 */

/*
 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {
 [super viewDidLoad];
 }
 */

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    //    SurfSlotMachineAppDelegate* del = (SurfSlotMachineAppDelegate*)[UIApplication sharedApplication].delegate;
    //    [del hideADS:YES];

    bErrorOnConnection = NO;
    self.lblProductTitle.hidden = YES;
    self.txtProductDescription.hidden = YES;
    self.txtGamecenterDescription.hidden = YES;
    self.txtRestoreDescription.hidden = YES;
    self.txtMoreGamesDescription.hidden = YES;
    self.btnBuyProduct.hidden = YES;
    self.btnRestore.hidden = YES;
    self.btnGameCenter.hidden = YES;
    self.btnMoreGame.hidden = YES;

    self.lblLoading.hidden = YES;
    self.activityIndicatorPurchasingView.hidden = YES;
    self.lblPurchasing.hidden = YES;
    self.unlockInfoImage.hidden = YES;

    // Check network reachability
    Reachability* reachability = [Reachability reachabilityWithHostName:@"www.google.com"];
    NetworkStatus internetStatus = [reachability currentReachabilityStatus];
    if (internetStatus != ReachableViaWiFi && internetStatus != ReachableViaWWAN) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
                                                        message:@"You require an internet connection via WiFi or cellular network for connecting to online store"
                                                       delegate:nil
                                              cancelButtonTitle:@"Dismiss"
                                              otherButtonTitles:nil];

        [alert show];
        [alert release];
        bErrorOnConnection = YES;
    }




    if ([SKPaymentQueue canMakePayments])
    {
        [self requestProductData];

    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"In-App Purchases are disabled"
                                                        message:@"Please check your restrictions for In-App Purchases in Settings->General->Restrictions."
                                                       delegate:nil
                                              cancelButtonTitle:@"Dismiss"
                                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        bErrorOnConnection = YES;
    }

    //timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
    //[timer retain];
}
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
    UIAlertView  *alert = [[[UIAlertView alloc] initWithTitle:@"In-App Store unavailable" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];

    [alert show];
}
- (void)setMainGameParent:(id) parent {
    mainGameParent = parent;
}

- (void)viewWillDisappear:(BOOL)animated {

    [super viewWillDisappear:animated];

    [timer invalidate];
    [timer release];
}

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];

    self.activityIndicatorView = nil;
    self.lblLoading = nil;
    self.lblProductTitle = nil;
    self.txtProductDescription = nil;
    self.txtRestoreDescription = nil;
    self.txtGamecenterDescription = nil;
    self.txtMoreGamesDescription = nil;
    self.btnBuyProduct = nil;
    self.btnGameCenter = nil;
    self.btnRestore = nil;
    self.btnMoreGame = nil;
    self.btnBuyProduct = nil;
    self.unlockInfoImage = nil;

    mainGameParent = nil;

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (IBAction) closePressed:(id) sender {
    [mainGameParent GameStoreClosed];
    [self.view removeFromSuperview];
}

- (IBAction) purchaseUnlock:(id) sender {

    UIActionSheet *Sheet=[[UIActionSheet alloc]initWithTitle:@"Option" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Super Coins",@"Unlock Payouts",@"RemoveAds", nil];
    [Sheet showInView:[UIApplication sharedApplication].keyWindow];

    //[self.view removeFromSuperview];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex==actionSheet.cancelButtonIndex) {

    }
    if (buttonIndex==0) {
        bool bPaymentInQueue = NO;
        for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
            if ([transaction.payment.productIdentifier isEqualToString:gUnlimitedCoins]) {
                bPaymentInQueue = YES;
                NSLog(@"Payment already in queue!");
                break;
            }
        }
        if (!bPaymentInQueue) {
            NSLog(@"Adding new payment...");
            SKPayment *payment = [SKPayment paymentWithProductIdentifier:gUnlimitedCoins];
            [[SKPaymentQueue defaultQueue] addPayment:payment];
        }
    }
    if (buttonIndex==1) {
        bool bPaymentInQueue = NO;
        for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
            if ([transaction.payment.productIdentifier isEqualToString:kPayoutUnlockProduct]) {
                bPaymentInQueue = YES;
                NSLog(@"Payment already in queue!");
                break;
            }
        }
        if (!bPaymentInQueue) {
            NSLog(@"Adding new payment...");
            SKPayment *payment = [SKPayment paymentWithProductIdentifier:kPayoutUnlockProduct];
            [[SKPaymentQueue defaultQueue] addPayment:payment];
        }
    }
    if (buttonIndex==2) {
        bool bPaymentInQueue = NO;
        for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
            if ([transaction.payment.productIdentifier isEqualToString:gRemoveads]) {
                bPaymentInQueue = YES;
                NSLog(@"Payment already in queue!");
                break;
            }
        }
        if (!bPaymentInQueue) {
            NSLog(@"Adding new payment...");
            SKPayment *payment = [SKPayment paymentWithProductIdentifier:gRemoveads];
            [[SKPaymentQueue defaultQueue] addPayment:payment];
        }
    }
}

- (IBAction) gameCenter:(id)sender {
    SurfSlotMachineAppDelegate* del = (SurfSlotMachineAppDelegate*)[UIApplication sharedApplication].delegate;
    RootViewController *rootViewController = del.viewController;
    [rootViewController showLeaderboard];
}

- (IBAction) restore:(id)sender {
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

- (IBAction) moreGames:(id)sender {
    SurfSlotMachineAppDelegate* del = (SurfSlotMachineAppDelegate*)[UIApplication sharedApplication].delegate;
    [del dispMoreApps];
}

- (void)requestProductData {

    lblLoading.hidden = NO;
    [activityIndicatorView startAnimating];

    SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kPayoutUnlockProduct]];
    request.delegate = self;
    [request start];
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    NSArray *myProducts = response.products;
    NSLog(@"%@",myProducts);
    if ([myProducts count] > 0) {
        SKProduct *product = [myProducts objectAtIndex:0];

        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
        [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
        [numberFormatter setLocale:product.priceLocale];
        NSString *priceString = [numberFormatter stringFromNumber:product.price];

        NSLog(@"Title: %@", product.localizedTitle);
        NSLog(@"Desc: %@", product.localizedDescription);
        NSLog(@"Price: %@", priceString);

        self.lblProductTitle.text = product.localizedTitle;
        self.txtProductDescription.text = product.localizedDescription;
        [self.btnBuyProduct setTitle:[NSString stringWithFormat:@"Choose your UPGRADE"] forState:UIControlStateNormal];
        [self.btnGameCenter setTitle:[NSString stringWithFormat:@"Leaderboard"] forState:UIControlStateNormal];
        [self.btnRestore setTitle:[NSString stringWithFormat:@"Restore"] forState:UIControlStateNormal];
        [self.btnMoreGame setTitle:[NSString stringWithFormat:@"More Games"] forState:UIControlStateNormal];

        self.lblProductTitle.hidden = NO;
        self.txtProductDescription.hidden = NO;
        self.txtGamecenterDescription.hidden = NO;
        self.txtRestoreDescription.hidden = NO;
        self.txtMoreGamesDescription.hidden = NO;
        self.btnBuyProduct.hidden = NO;
        self.btnGameCenter.hidden = NO;
        self.btnRestore.hidden = NO;
        self.btnMoreGame.hidden = NO;
        self.unlockInfoImage.hidden = NO;

        [numberFormatter release];
    }

    lblLoading.hidden = YES;
    [activityIndicatorView stopAnimating];

    [request release];
}


- (void)tick:(id)sender {

    bool bPaymentInQueue = NO;
    for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
        if ([transaction.payment.productIdentifier isEqualToString:kPayoutUnlockProduct]) {

            bPaymentInQueue = YES;
            break;
        }
    }


    if (bPaymentInQueue) {
        [self.activityIndicatorPurchasingView startAnimating];
        self.activityIndicatorPurchasingView.hidden = NO;
        self.lblPurchasing.hidden = NO;
        self.btnReturn.enabled = NO;
        self.btnBuyProduct.enabled = NO;
    } else {
        [self.activityIndicatorPurchasingView stopAnimating];
        self.activityIndicatorPurchasingView.hidden = YES;
        self.lblPurchasing.hidden = YES;
        self.btnReturn.enabled = YES;
        self.btnBuyProduct.enabled = YES;
    }

    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    if ([userDefault objectForKey:KEY_PAYOUTLOCKED] != nil && [userDefault boolForKey:KEY_PAYOUTLOCKED] == NO) {
        [mainGameParent GameStoreClosed];
        [self.view removeFromSuperview];
    }

    if (bErrorOnConnection) {
        [mainGameParent GameStoreClosed];
        [self.view removeFromSuperview];
    }
}
@end

您没有声明这些:

gRemoveads 

gUnlimitedCoins

范围/块中缺少这些声明。

看起来从未声明或设置过语句“ transaction.payment.productIdentifier isEqualToString:gRemoveads”中的变量“ gRemoveads”。 从计算机的角度来看,此变量不存在。 您知道此变量是什么还是应该在哪里设置?

还是那些应该是字符串文字? 与确切的文字“ gRemoveads”相同。 在这种情况下,请用引号引起来。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM