http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorialからアプリ内購入を行っています。reload
メソッドの外で積の配列を印刷しようとすると、エラーが発生します。menuitem アクションでこの製品配列を使用したいと考えています。配列の正しいサイズも表示されますが、その配列で製品を印刷または使用しようとするとエラーが発生します。
-(id) init
{
if( (self=[super init]))
{
isTouchEnabled=YES;
startY=120;
startX=90;
CCMenuItemImage *menuitem1 = [CCMenuItemImage itemFromNormalImage:@"100.png" selectedImage:@"100.png" target:self selector:@selector(buy100C:)];
CCMenuItemImage *menuitem2 = [CCMenuItemImage itemFromNormalImage:@"220.png" selectedImage:@"220.png" target:self selector:@selector(buy220C:)];
CCMenuItemImage *menuitem3 = [CCMenuItemImage itemFromNormalImage:@"350.png" selectedImage:@"350.png" target:self selector:@selector(buy350C:)];
CCMenuItemImage *menuitem4 = [CCMenuItemImage itemFromNormalImage:@"500.png" selectedImage:@"500.png" target:self selector:@selector(buy500C:)];
CCMenuItemImage *menuitem5 = [CCMenuItemImage itemFromNormalImage:@"1800.png" selectedImage:@"1800.png" target:self selector:@selector(buy1800C:)];
CCMenuItemImage *menuitem6 = [CCMenuItemImage itemFromNormalImage:@"3000.png" selectedImage:@"3000.png" target:self selector:@selector(buy3000C : )];
CCMenuItemImage *menuitem7 = [CCMenuItemImage itemFromNormalImage:@"back2.png" selectedImage:@"back2.png" target:self selector:@selector(back)];
CCMenu *menu = [CCMenu menuWithItems:menuitem1,menuitem2,menuitem3,menuitem4,menuitem5,menuitem6,menuitem7, nil];
[menu alignItemsVerticallyWithPadding:2];
menu.position=ccp(startX, startY);
menu.scale=.55;
[self addChild:menu];
[RageIAPHelper sharedInstance];
[self reload];
}
return self;
}
-(void)reload
{
[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
NSLog(@"produts==%d",[_products count]);
NSLog(@"product===%@",_products);
for (SKProduct * skProduct in _products) {
NSLog(@"Found product: %@ %@ %0.2f",
skProduct.productIdentifier,
skProduct.localizedTitle,
skProduct.price.floatValue);
}
}
}];
}
-(void)buy100C:(id) sender
{
NSLog(@"hisize=======%d",[_products count]);
if([_products count] >=8){
NSLog(@"product===%@",_products);//this line is giving error and app stop.
}
}
ここで buy100C メソッドでは、配列から製品を取得していません。