如何为按钮应用升级(在app Purchase中)?

时间:2015-02-18 07:36:03

标签: ios

我已经在AppStore中完成了一个photoEditorApp。现在我想仅为一些按钮应用InApppurchage。在我的应用程序覆盖按钮就在那里,当我们点击该按钮时,我们得到7个按钮,其中3个按钮免费剩余4个按钮供购买。因为我已经写了这样的代码。但是它不工作不知道我在哪里做错了所以请任何人建议如何做UIScrollView * scrollView;

-(void)createScrolling2
{
previousButtonTag=1000;
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 4, self.overlaysView.frame.size.width, 106)];
int x =0.5;
for (int i = 0; i<8; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(x, 0, 100, 100);
button.layer.borderWidth=0.5;
button.titleLabel.font=[UIFont boldSystemFontOfSize:12];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
button.layer.borderColor=[[UIColor lightGrayColor]CGColor];
button.tag = i;

if (subButtonTag == 101) {
[button setBackgroundImage:[self.fireworksArray objectAtIndex:i] forState:UIControlStateNormal];

}
else if (subButtonTag == 102){
[button setBackgroundImage:[self.flowersArray objectAtIndex:i] forState:UIControlStateNormal];
}
else if (subButtonTag == 103){
[button setBackgroundImage:[self.loveArray objectAtIndex:i] forState:UIControlStateNormal];
}
else if (subButtonTag == 104){
[button setBackgroundImage:[self.rainbowArray objectAtIndex:i] forState:UIControlStateNormal];
} 
int previousButtonTag;

-(void)OverLayMethod:(UIButton*)sender{

UIButton *selectButton = (UIButton*)sender;
NSLog(@"hi %d",sender.tag);
previousButtonTag=selectButton.tag;
NSLog(@"hi %d",sender.tag);
UIImage *selectImage;

if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){
if (subButtonTag == 101) {
selectImage = [self.fireworksArray objectAtIndex:sender.tag];
NSLog(@"selectImage = %@",selectImage);
self.overlayImgView.image = selectImage;

}
else if (subButtonTag == 102){

selectImage = [self.flowersArray objectAtIndex:sender.tag];
NSLog(@"selectImage = %@",selectImage);
self.overlayImgView.image = selectImage;

}

else if (subButtonTag == 103){

selectImage = [self.loveArray objectAtIndex:sender.tag];
NSLog(@"selectImage = %@",selectImage);
self.overlayImgView.image = selectImage;

}
else if (subButtonTag == 104){

selectImage = [self.rainbowArray objectAtIndex:sender.tag];
NSLog(@"selectImage = %@",selectImage);
self.overlayImgView.image = selectImage;

}
- (IBAction)buyPackClicked:(id)sender
{
if (![demoPurchase restorePurchase])
{
UIAlertView *settingsAlert = [[UIAlertView alloc] initWithTitle:@"Allow Purchases" message:@"You must first enable In-App Purchase in your iOS Settings before restoring a previous purchase." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[settingsAlert show];

}
}
- (IBAction)restorePreviousClicked:(id)sender
{
  if (demoPurchase.validProduct != nil)
{
if (![demoPurchase purchaseProduct:demoPurchase.validProduct])
{
UIAlertView *settingsAlert = [[UIAlertView alloc] initWithTitle:@"Allow Purchases" message:@"You must first enable In-App Purchase in your iOS Settings before making this purchase." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[settingsAlert show];

}
}
}
-(void) requestedProduct:(EBPurchase*)ebp identifier:(NSString*)productId name:(NSString*)productName price:(NSString*)productPrice description:(NSString*)productDescription
{
SKProduct *product = ebp.validProduct; // epb is the EBPurchase object
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
NSString *formattedPrice = [numberFormatter stringFromNumber:product.price];
NSLog(@"ViewController requestedProduct %@",productPrice);
if (productPrice != nil)
{
[buyPack setTitle:[@"Buy Pack item " stringByAppendingString:productPrice] forState:UIControlStateNormal];
buyPack.enabled = YES; // Enable buy button.

} 
else {
buyPack.enabled = NO; // Ensure buy button stays disabled.
[buyPack setTitle:@"Buy Pack item" forState:UIControlStateNormal];

UIAlertView *unavailAlert = [[UIAlertView alloc] initWithTitle:@"Not Available" message:@"This In-App Purchase item is not available in the App Store at this time. Please try again later." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[unavailAlert show];

}

}

-(void) successfulPurchase:(EBPurchase*)ebp restored:(bool)isRestore identifier:(NSString*)productId receipt:(NSData*)transactionReceipt
{
NSLog(@"ViewController successfulPurchase");

if (!isPurchased)
{
isPurchased = YES;
NSString *alertMessage;

if (isRestore) {
alertMessage = @"Your purchase was restored and the Game Levels Pack is now unlocked for your enjoyment!";

 } else {
 alertMessage = @"Your purchase was successful and the Game Levels Pack is now unlocked for your enjoyment!";
 }

 UIAlertView *updatedAlert = [[UIAlertView alloc] initWithTitle:@"Thank You!" message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
 [updatedAlert show];

 }
 }

 -(void) failedPurchase:(EBPurchase*)ebp error:(NSInteger)errorCode message:(NSString*)errorMessage
 {
 NSLog(@"ViewController failedPurchase");
 UIAlertView *failedAlert = [[UIAlertView alloc] initWithTitle:@"Purchase Stopped" message:@"Either you cancelled the request or Apple reported a transaction error. Please try again later, or contact the app's customer support for assistance." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
 [failedAlert show];

 }

 -(void) incompleteRestore:(EBPurchase*)ebp
 {
 NSLog(@"ViewController incompleteRestore");
 UIAlertView *restoreAlert = [[UIAlertView alloc] initWithTitle:@"Restore Issue" message:@"A prior purchase transaction could not be found. To restore the purchased product, tap the Buy button. Paid customers will NOT be charged again, but the purchase will be restored." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[restoreAlert show];


}

-(void) failedRestore:(EBPurchase*)ebp error:(NSInteger)errorCode message:(NSString*)errorMessage
{
NSLog(@"ViewController failedRestore");
UIAlertView *failedAlert = [[UIAlertView alloc] initWithTitle:@"Restore Stopped" message:@"Either you cancelled the request or your prior purchase could not be restored. Please try again later, or contact the app's customer support for assistance." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[failedAlert show];

}

在这里,当我想点击那4个按钮中的任何一个按钮,获得购买透明费用的警报。

0 个答案:

没有答案