Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何为按钮应用升级(inappPurchage)?_Ios - Fatal编程技术网

Ios 如何为按钮应用升级(inappPurchage)?

Ios 如何为按钮应用升级(inappPurchage)?,ios,Ios,我已经做了一个photoEditorApp,它在AppStore中。现在我只想对一些按钮应用InApppurchage。在我的应用程序中,当我们点击该按钮时,overlays按钮就在那里,我们得到了7个按钮,其中3个按钮是免费的,其余4个按钮是购买的。为此,我编写了这样的代码。但它不起作用。我不知道我哪里出错了,所以请任何人建议如何使用UIScrollView*scrollView -(void)createScrolling2 { previousButtonTag=1000; if (UI_

我已经做了一个photoEditorApp,它在AppStore中。现在我只想对一些按钮应用InApppurchage。在我的应用程序中,当我们点击该按钮时,overlays按钮就在那里,我们得到了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];

}
-(无效)创建滚动2
{
previousButtonTag=1000;
if(UI\u USER\u INTERFACE\u IDIOM()==UIUserInterfaceIdiomPad){
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,4,self.overlyView.frame.size.width,106)];
int x=0.5;
对于(int i=0;i