大佬教程收集整理的这篇文章主要介绍了iOS IAP不能在ipv6上工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
// // 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 *httpBodyString=[[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",[httpBodyString length]]; [urlrequest SETVALue:postLength forhttpHeaderField:@"Content-Length"]; [urlrequest SETVALue:@"application/x-www-form-urlencoded" forhttpHeaderField:@"Content-Type"]; [urlrequest sethttpR_937_11845@ethod:@"POST"]; [urlrequest sethttpBody:[httpBodyString dataUsingEncoding:NSISOlatin1StringEncoding]]; [httpBodyString 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_I@L_326_13@m() == UIUserInterfaceI@L_326_13@mPad ) { 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_I@L_326_13@m() == UIUserInterfaceI@L_326_13@mPad){ //[[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_I@L_326_13@m() == UIUserInterfaceI@L_326_13@mPad){ //[[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]; //NShttpURLResponse *httpResponse = (NShttpURLResponse*)response; if ([response respondsToSELEctor:@SELEctor(allHeaderFields)]) { //NSDictionary *Dictionary = [httpResponse 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上工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。