iphone - NSArray how do I restrict data in array when app not purchased? -


i have app has total of 32 images appear @ random;

i that, if user has not purchased particular upgrade first 16 (f1.png - f16.png only) array show, if have bought purchase, 32 available @ random.

the in-app id's allow of images are;

com.myphotofun.upgrade16more & com.myphotofun.complete

the code call random array is;

-(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]; } 

now changed (with 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];  } 

any code assistance appreciated. thanks,

chris

-(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];      nsinteger index = arc4random_uniform([[nsuserdefaults standarduserdefaults] boolforkey:product_purchased] ? 32 : 16);      uiimage *myimage = [uiimage imagenamed:[myimagenames objectatindex:index]];      [paintingimage setimage:myimage]; } 

don't forget set value when product purchased

[[nsuserdefaults standarduserdefaults] setbool:yes forkey:product_purchased]; [[nsuserdefaults standarduserdefaults] synchronize]; 

also if images named have shown prefer accessing them dynamic strings instead of storing them in nsarray:

    nsinteger index = arc4random_uniform([[nsuserdefaults standartuserdefaults] boolforkey:product_purchased] ? 32 : 16);      uiimage *myimage = [uiimage imagenamed:[nsstring stringwithformat:@"f%d.png",index + 1]]; 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -