我有一个应用程序,共有 32 张随机出现的图像;
我希望这样,如果用户没有购买特定的升级,那么只有阵列中的前 16 个(仅 f1.png - f16.png)会显示,但是如果他们购买了购买,那么所有 32将随机提供。
允许所有图像的应用内 ID 是;
com.myphotofun.upgrade16more & com.myphotofun.complete
调用随机数组的代码是;
-(void)randImage
{
NSArray *myImageNames = [NSArray arrayWithObjects:@"f1.png", @"f2.png", @"f3.png",@"f4.png",@"f5.png",@"f6.png",@"f7.png",@"f8.png",@"f9.png",@"f10.png",@"f11.png",@"f12.png",@"f13.png",@"f14.png",@"f15.png",@"f16.png","f17.png","f18.png","f19.png","f20.png","f21.png","f22.png","f23.png","f24.png","f25.png","f26.png","f27.png","f28.png","f29.png","f30.png","f31.png","f32.png",nil];
int index = arc4random() % [myImageNames count];
UIImage *myImage = [UIImage imageNamed:[myImageNames objectAtIndex:index]];
[PaintingImage setImage:myImage];
}
现在改为(感谢 guenis);
-(void)randImage
{
NSInteger index = arc4random_uniform([[NSUserDefaults standardUserDefaults] boolForKey:PRODUCT_PURCHASED] ? 32 : 16);
UIImage *myImage = [UIImage imageNamed:[NSString stringWithFormat:@"f%d.png",index +1]];
[PaintingImage setImage:myImage];
}
任何代码帮助将不胜感激。谢谢,
克里斯