//// VIEwController.m//NSMutableArray * arrayOfSection;NSMutableArray * sectionheaders;Nsstring *error;#import "CoinsController.h"#import "Nsstring+SBJsON.h"#import <CommonCrypto/CommonDigest.h>@implementation CoinsController@synthesize bkg;-(voID) callPurchaseID:(Nsstring*)iAPId amount:(NSUInteger)ncoins{ SKPayment *payment = [SKPayment paymentWithProductIDentifIEr:iAPId]; //[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [[SKPaymentQueue defaultQueue] addPayment:payment]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.9; [UIVIEw commitAnimations]; loadingtext.text = @"Processing Purchase"; NSLog(@"Processing Purhcase"); // currentGem = [Nsstring stringWithFormat:@"vegas%@",@"80k"]; [CommonUtilitIEs encryptString:[Nsstring stringWithFormat:@"%lu",(unsigned long)ncoins]:@"c"]; NSLog(@"Processing");}- (IBAction)purchaseCoins:(ID)sender{ UIbutton *button = (UIbutton *)sender; NSLog(@"%li",(long)button.tag); switch (button.tag) { case 1001: [self callPurchaseID:IAP1 amount:IAP_AMT_1]; break; case 1002: [self callPurchaseID:IAP2 amount:IAP_AMT_2]; break; case 1003: [self callPurchaseID:IAP3 amount:IAP_AMT_3]; break; case 1004: [self callPurchaseID:IAP4 amount:IAP_AMT_4]; break; case 1005: [self callPurchaseID:IAP5 amount:IAP_AMT_5]; break; case 1006: [self callPurchaseID:IAP6 amount:IAP_AMT_6]; break; default: break; }}-(voID) vIEwWillAppear:(BOol)animated{ [super vIEwWillAppear:animated]; NSNumberFormatter* nf = [[NSNumberFormatter alloc] init]; nf.usesGrouPingSeparator = YES; nf.grouPingSize = 3; ((UILabel*)[self.vIEw vIEwWithTag:2001]).text = [Nsstring stringWithFormat:@"%@ Coins",[nf stringFromNumber:[NSNumber numberWithInteger:IAP_AMT_1]]]; ((UILabel*)[self.vIEw vIEwWithTag:2002]).text = [Nsstring stringWithFormat:@"%@ Coins",[nf stringFromNumber:[NSNumber numberWithInteger:IAP_AMT_2]]]; ((UILabel*)[self.vIEw vIEwWithTag:2003]).text = [Nsstring stringWithFormat:@"%@ Coins",[nf stringFromNumber:[NSNumber numberWithInteger:IAP_AMT_3]]]; ((UILabel*)[self.vIEw vIEwWithTag:2004]).text = [Nsstring stringWithFormat:@"%@ Coins",[nf stringFromNumber:[NSNumber numberWithInteger:IAP_AMT_4]]]; ((UILabel*)[self.vIEw vIEwWithTag:2005]).text = [Nsstring stringWithFormat:@"%@ Coins",[nf stringFromNumber:[NSNumber numberWithInteger:IAP_AMT_5]]]; ((UILabel*)[self.vIEw vIEwWithTag:2006]).text = [Nsstring stringWithFormat:@"%@ Coins",[nf stringFromNumber:[NSNumber numberWithInteger:IAP_AMT_6]]]; [nf release];}- (voID)requestProUpgradeProductData{ NSLog(@"called productsRequest"); [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.9; [UIVIEw commitAnimations]; loadingtext.text = @"Connecting to Store"; if([cost1000.text isEqual:@"0.00"]){ NSSet *productIDentifIErs = [NSSet setWithObjects:IAP1,IAP2,IAP3,IAP4,IAP5,IAP6,nil]; SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIDentifIErs:productIDentifIErs]; productsRequest.delegate = self; [productsRequest start]; }else{ [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations]; }}- (voID)productsRequest:(SKProductsRequest *)request dIDReceiveResponse:(SKProductsResponse *)response{ Nsstring *sym = @""; NSArray *items = response.products; for(SKProduct *itemproduct in items) { NSLog(@"Product Title: %@ - %@",itemproduct.localizedTitle,itemproduct.priceAsstring); //NSLog(@"Product description: %@",item.localizedDescription); //NSLog(@"Product price: ",; NSLog(@"Product ID: %@",itemproduct.productIDentifIEr); if([itemproduct.productIDentifIEr isEqual:IAP1]){ cost1000.text = [sym stringByAppendingString:[Nsstring stringWithFormat:@"%@",itemproduct.priceAsstring]]; }else if([itemproduct.productIDentifIEr isEqual:IAP2]){ cost3200.text = [sym stringByAppendingString:[Nsstring stringWithFormat:@"%@",itemproduct.priceAsstring]]; }else if([itemproduct.productIDentifIEr isEqual:IAP3]){ cost8000.text = [sym stringByAppendingString:[Nsstring stringWithFormat:@"%@",itemproduct.priceAsstring]]; }else if([itemproduct.productIDentifIEr isEqual:IAP4]){ cost20000.text = [sym stringByAppendingString:[Nsstring stringWithFormat:@"%@",itemproduct.priceAsstring]]; }else if([itemproduct.productIDentifIEr isEqual:IAP5]){ cost80000.text = [sym stringByAppendingString:[Nsstring stringWithFormat:@"%@",itemproduct.priceAsstring]]; }else if([itemproduct.productIDentifIEr isEqual:IAP6]){ cost200000.text = [sym stringByAppendingString:[Nsstring stringWithFormat:@"%@",itemproduct.priceAsstring]]; } } for (Nsstring *invalIDProductID in response.invalIDProductIDentifIErs) { NSLog(@"InvalID product ID: %@",invalIDProductID); error = @"YES"; } if([error isEqual:@"YES"]){ UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Payments Error Occured" message:@"Could not read payment information from Apple in-app Servers. Please try again later" delegate:nil cancelbuttonTitle:@"Ok" otherbuttonTitles:nil,nil]; [alert show]; [alert release]; [self dismissVIEwControllerAnimated:YES completion:nil]; error = @"NO"; } // finally release the reqest we alloc/init’ed in requestProUpgradeProductData //[productsRequest release]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations];}//// removes the transaction from the queue and posts a notification with the transaction result//- (voID)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:(BOol)wasSuccessful{ // remove the transaction from the payment queue. [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; if (wasSuccessful) {#ifdef kURL_VERIFY_PURCHASE_RECEIPT Nsstring *JsonObjectString = [CommonUtilitIEs encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length]; ////NSLog(JsonObjectString); [CommonUtilitIEs encryptString:[CommonUtilitIEs md5:JsonObjectString]:@"b"]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.9; [UIVIEw commitAnimations]; //loadingtext.text = @"Purchase Completing"; loadingtext.text = @"Completing Transaction"; Nsstring *@R_301_6822@BodyString=[[Nsstring alloc] initWithFormat:@"receipt=%@&userID=%@",JsonObjectString,[CommonUtilitIEs decryptString:@"username"]]; Nsstring *urlString=kURL_VERIFY_PURCHASE_RECEIPT; NSURL *url=[[NSURL alloc] initWithString:urlString]; [urlString release]; NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url]; [url release]; Nsstring *postLength = [Nsstring stringWithFormat:@"%d",[@R_301_6822@BodyString length]]; [urlRequest setValue:postLength for@R_301_6822@headerFIEld:@"Content-Length"]; [urlRequest setValue:@"application/x-www-form-urlencoded" for@R_301_6822@headerFIEld:@"Content-Type"]; [urlRequest set@R_301_6822@Method:@"POST"]; [urlRequest set@R_301_6822@Body:[@R_301_6822@BodyString dataUsingEnCoding:NSISOlatin1StringEnCoding]]; [@R_301_6822@BodyString release]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; responseData=[[NSMutableData data] retain];#else int addCoins = [[CommonUtilitIEs decryptString:@"c"] intValue]; int currentCoins = [[CommonUtilitIEs decryptString:@"coins"] intValue]; int newCoins = addCoins + currentCoins; [CommonUtilitIEs encryptString:[Nsstring stringWithFormat:@"%i",newCoins]:@"coins"]; // due to sync issues we add + 1 to xp so sync to server completes NSLog(@"transaction complete"); [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;#endif } else { NSLog(@"Purchase Failed"); // send out a notification for the Failed transaction NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction,@"transaction",nil]; //[[NSNotificationCenter defaultCenter] postNotificationname:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations]; }}//// called when the transaction was successful//- (voID)completeTransaction:(SKPaymentTransaction *)transaction{ [self finishTransaction:transaction wasSuccessful:YES];}//// called when a transaction has Failed//- (voID)FailedTransaction:(SKPaymentTransaction *)transaction{ if (transaction.error.code != SKErrorPaymentCancelled) { // error! [self finishTransaction:transaction wasSuccessful:NO]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations]; NSLog(@"error transaction"); } else { // this is fine,the user just cancelled,so don’t notify [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations]; NSLog(@"cancelled transaction"); }}//// called when the transaction status is updated//- (voID)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchased: [self completeTransaction:transaction]; break; case SKPaymentTransactionStateFailed: [self FailedTransaction:transaction]; break; default: break; } }}#pragma mark -- (IBAction)closeCoins:(ID)sender{ [self dismissVIEwControllerAnimated:YES completion:nil];}- (voID)vIEwDIDLoad{ [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; webVIEw.opaque = NO; webVIEw.backgroundcolor = [UIcolor clearcolor]; webVIEw.dataDetectorTypes = UIDataDetectorTypelink; jackpotVIEw.opaque = NO; jackpotVIEw.backgroundcolor = [UIcolor clearcolor]; //[self dIDLoad]; Nsstring *filename = @"store.jpg"; CGRect screenRect = [[UIScreen mainScreen] bounds]; if (screenRect.size.wIDth == 568.0f) { filename = [filename stringByReplacingOccurrencesOfString:@".jpg" withString:@"-568h@2x.jpg"]; [self.bkg setBounds:CGRectMake(0,screenRect.size.wIDth,screenRect.size.height)]; NSLog(@"YAGO - changing background: %@",filename); } if ( UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad ) { filename = @"store-ipad.jpg"; } self.bkg.image = [UIImage imagenamed:filename]; vIEwLoading.Alpha = 0.0; vIEwNoInternet.Alpha = 0.0; // reachability [self tryConnect:nil]; if([SKPaymentQueue canMakePayments]){ ////NSLog(@"can make payments"); [self requestProUpgradeProductData]; }else{ ////NSLog(@"cannot make payments"); UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Payments Disabled" message:@"in-app Purchases are Disabled on this device." delegate:nil cancelbuttonTitle:@"Ok" otherbuttonTitles:nil,nil]; [alert show]; [alert release]; [self dismissVIEwControllerAnimated: YES completion:nil]; } CGSize result = [[UIScreen mainScreen] bounds].size; CGfloat scale = [UIScreen mainScreen].scale; result = CGSizeMake(result.wIDth * scale,result.height * scale); if(result.height == 960){ bar.frame = CGRectMake(0,(result.height / 2),32); }else if(result.height == 1136){ bar.frame = CGRectMake(0,32); }else if(result.height == 1024){ bar.frame = CGRectMake(0,result.height,44); }else if (result.height == 2048){ bar.frame = CGRectMake(0,result.height/2,44); } else{ bar.frame = CGRectMake(0,(result.height),32); } int FontSize = 16; if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad){ //[[UILabel appearance] setFont:[UIFont FontWithname:@"Myriad Web Pro" size:28.0]]; }else{ //[[UILabel appearance] setFont:[UIFont FontWithname:@"Myriad Web Pro" size:12.0]]; FontSize = 12; } UIbarbuttonItem *backbutton = [[[UIbarbuttonItem alloc] initWithTitle:@"Close" style:UIbarbuttonItemStylebordered target:nil action:nil] autorelease]; UIImage *buttonBack32 = [[UIImage imagenamed:@"NavigationBackbutton"] resizableImageWithCAPInsets:UIEdgeInsetsMake(0,10,5)]; [[UIbarbuttonItem appearance] setBackbuttonBackgroundImage:buttonBack32 forState:UIControlStatenormal barMetrics:UIbarMetricsDefault]; [[UIbarbuttonItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIcolor whitecolor],UITextAttributeTextcolor,[UIcolor colorWithRed:0.0 green:0.0 blue:0.0 Alpha:0.8],UITextAttributeTextShadowcolor,[NSValue valueWithUIOffset:UIOffsetMake(0,-1)],UITextAttributeTextShadowOffset,[UIFont FontWithname:@"Helvetica-Bold" size:FontSize],UITextAttributeFont,nil] forState:UIControlStatenormal]; self.navigationItem.backbarbuttonItem = backbutton;}-(voID)vIEwWilldisappear:(BOol)animated{ NSLog(@"coins has gone"); [[NSNotificationCenter defaultCenter] postNotificationname:@"updateCoins" object:self]; [[NSNotificationCenter defaultCenter] postNotificationname:@"sortCoins" object:self]; if (UI_USER_INTERFACE_IdioM() == UIUserInterfaceIdiomPad){ //[[UILabel appearance] setFont:[UIFont FontWithname:@"Myriad Web Pro" size:20.0]]; }else{ //[[UILabel appearance] setFont:[UIFont FontWithname:@"Myriad Web Pro" size:10.0]]; }}- (NSUInteger)supportedInterfaceOrIEntations { return UIInterfaceOrIEntationMaskLandscape;}- (BOol) shouldautorotate { return YES;}- (BOol)shouldautorotatetoInterfaceOrIEntation: (UIInterfaceOrIEntation)interfaceOrIEntation { // Return YES for supported orIEntations if(interfaceOrIEntation == UIInterfaceOrIEntationLandscapeleft || interfaceOrIEntation == UIInterfaceOrIEntationLandscapeRight){ return YES; }else{ return NO; }}- (voID)dealloc { [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; [self.bkg release]; [super dealloc];}#pragma mark for server sIDe valIDation (no customer support)// these connection-related methods are only here to help in case you ever decIDe to implement// server-sIDe valIDation of purchase receipts// - in this case,you'll also need to define your own kURL_VERIFY_PURCHASE_RECEIPT and figure out the existing valIDation protocol (I can't provIDe you with support on this one,it's code written by someone else)- (voID)connection:(NSURLConnection *)connection dIDReceiveResponse:(NSURLResponse *)response { [responseData setLength:0]; //NS@R_301_6822@URLResponse *@R_301_6822@Response = (NS@R_301_6822@URLResponse*)response; if ([response respondsToSelector:@selector(allheaderFIElds)]) { //NSDictionary *dictionary = [@R_301_6822@Response allheaderFIElds]; //NSLog([dictionary description]); }}- (voID)connection:(NSURLConnection *)connection dIDReceiveData:(NSData *)data { [responseData appendData:data]; //Nsstring *a = [[Nsstring alloc] initWithData:data enCoding:NSUTF8StringEnCoding]; //NSLog(@"Data: %@",a);}- (voID)connection:(NSURLConnection *)connection dIDFailWithError:(NSError *)error { UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"No Connection" message:@"You are not connected to the internet or data. Please connect and try again." delegate:nil cancelbuttonTitle:@"Cancel" otherbuttonTitles:nil,nil]; [alert show]; [alert release];}- (voID)connectionDIDFinishLoading:(NSURLConnection *)connection { Nsstring *responseString = [[Nsstring alloc] initWithData:responseData enCoding:NSUTF8StringEnCoding]; //////NSLog(responseString); Nsstring *gKey = [CommonUtilitIEs decryptString:@"b"]; Nsstring *result = [CommonUtilitIEs base64Decrypt:responseString:gKey]; NSLog(@"%@",result); int r = [result intValue]; ////NSLog(@"r int: %i",r); if(r == 1){ int addCoins = [[CommonUtilitIEs decryptString:@"c"] intValue]; int currentCoins = [[CommonUtilitIEs decryptString:@"coins"] intValue]; int newCoins = addCoins + currentCoins; [CommonUtilitIEs encryptString:[Nsstring stringWithFormat:@"%i",newCoins]:@"coins"]; // due to sync issues we add + 1 to xp so sync to server completes NSLog(@"transaction complete"); }else{ UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"Receipt Failed" message:@"Please make the purchase again using a vaild iTunes account" delegate:nil cancelbuttonTitle:@"Cancel" otherbuttonTitles:nil,nil]; [alert show]; [alert release]; } [self dismissVIEwControllerAnimated:YES completion:nil]; [UIVIEw setAnimationDuration:0.5]; [UIVIEw setAnimationDelegate:self]; [UIVIEw setAnimationDIDStopSelector:@selector(fadeOut:finished:context:)]; vIEwLoading.Alpha = 0.0; [UIVIEw commitAnimations]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;}@end
我不知道这段代码有什么问题.我在xcode调试日志中唯一得到的是“购买失败”.
任何帮助将受到高度赞赏.
不知道为什么他们第一次拒绝了我的应用程序,但是在我重新提交之后它被批准了.
总结以上是内存溢出为你收集整理的iOS IAP不能在ipv6上工作全部内容,希望文章能够帮你解决iOS IAP不能在ipv6上工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)