2021年4月27日星期二

IAP issue in iOS 14

I'm a small developer and I'm struggling to fix an error I get only under iOS 14. Now I can't restore my IAPs. I developed a Children app, that has books. After the books have been purchased and downloaded, if the user deletes them or delete the app, they can't restore the purchases. But this only happens on iOS 14. Any help would be deeply appreciated.

These are the steps and errors we get along the way.

Step1: Purchase product Step2: Wait for download contain Step3: Once the download contain complete remove app and install again Step4: Tap on a product that you buy last time to restore this particular product Step5: After restore success received restored transactions and start product content downloading Step6: Once downloading finished "SKDownloadStateFinished" call and get the download.contentURL.absoluteString Step7: After copy the downloaded content from "Caches" to another place issue has occurred.

• System information (device model and OS version number) IOS 14.2 IPhone 11 Also on iPad Pro 9.7 iOS 14.4

But I assume this error happens on all devices.

ViewController.m

//  //  ViewController.m  //  cocos2d_libs  //  //  Created by AR on 27/04/21.  //      -(void)moveAssetsFromCachesToLocal:(NSString*)bookName cachePath:(NSString*)tempPath  {      NSLog(@"Temporary File :%@\n", tempPath);      NSLog(@"Temporary URL :%@\n",[NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:tempPath.lastPathComponent]]);      NSLog(@"[self assetsUnzipPath:bookName] File :%@\n", [self assetsUnzipPath:bookName]);      NSString *zipFolderPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:[tempPath.lastPathComponent stringByAppendingString:@"/Contents"]];      if (@available(iOS 14, *))      {          std::string text = [zipFolderPath UTF8String];          std::string textfind = "Caches/";          std::size_t found = text.find(textfind);          if (found != std::string::npos){              text.insert(found + textfind.size(),"StoreKit/");              zipFolderPath = [NSString stringWithUTF8String:text.c_str()];          }      }      NSString *destinationPath = [self assetsUnzipPath:bookName];      dispatch_queue_t queue = dispatch_queue_create("DISPATCH_QUEUE_CONCURRENT",DISPATCH_QUEUE_CONCURRENT);      dispatch_async(queue, ^{          NSError *error = nil;          NSFileManager *fileManager = [[NSFileManager alloc] init];          BOOL isMoved = false;          BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:destinationPath];          if (fileExists)              isMoved = true;          else              isMoved = [fileManager copyItemAtPath:zipFolderPath toPath:destinationPath error:&error];          if (isMoved)          {              NSLog(@"unzipping");              NSString *str = [self assetsDestinationPath:bookName];              dispatch_async(dispatch_get_main_queue(), ^{                  [[MyScrollView sharedScrollView] stop_animation];              });              BOOL success = [SSZipArchive unzipFileAtPath:[destinationPath stringByAppendingString:[NSString stringWithFormat:@"%@%@", bookName, @"AllAssets.zip"]] toDestination:str];                  if (!success)                  {                      [self showIAPFailMessage:bookName];                      return;                  }                  else                  {                            dispatch_async(dispatch_get_main_queue(), ^{                              g_pBookManager->onUnzipSuccess([bookName UTF8String]);                              g_pBookManager->getButton([bookName UTF8String])->canChangedToState(EButtonState::DOWNLOAD_COMPLETE);                          });                      if (!isiPhone_XR)                      {                          NSString *strBookPath = [NSString stringWithFormat:@"%@%@", bookName, @"AllAssets"];                          [[NSFileManager defaultManager] removeItemAtPath:[self assetsUnzipPath:bookName] error:nil];                          if (Application::getInstance()->getTargetPlatform() == cocos2d::Application::Platform::OS_IPHONE)                          {                              if (cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().width < 2048 && cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().height < 1536)                              {                                  if (isiPhone_XR)                                  {                                      NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images",                                                                   [self assetsDestinationPath:bookName], strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil];                                      NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images",                                                                            [self assetsDestinationPath:bookName], strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil];                                      NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images",                                                                              [self assetsDestinationPath:bookName], strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil];                                      NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images",                                                                           [self assetsDestinationPath:bookName], strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil];                                  }                                  else                                  {                                      NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/HD_images",                                                                      [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil];                                      NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/HD_images",                                                                            [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil];                                      NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/HD_images",                                                                              [self assetsDestinationPath:bookName], strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil];                                      NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/HD_images",                                                                           [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil];                                  }                              }                              else                              {                                  NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images",                                                               [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil];                                  NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images",                                                                        [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil];                                  NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images",                                                                          [self assetsDestinationPath:bookName], strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil];                                  NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images",                                                                       [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil];                              }                          }                          else if (Application::getInstance()->getTargetPlatform() == cocos2d::Application::Platform::OS_IPAD)                          {                              if (cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().width < 2048 && cocos2d::Director::getInstance()->getOpenGLView()->getFrameSize().height < 1536)                              {                                  if (isiPhone_XR)                                  {                                      NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images",                                                                   [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil];                                      NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images",                                                                            [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil];                                      NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images",                                                                              [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil];                                      NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images",                                                                           [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil];                                  }                                  else                                  {                                      NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/HD_images",                                                                   [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil];                                      NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/HD_images",                                                                            [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil];                                      NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/HD_images",                                                                              [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil];                                      NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/HD_images",                                                                           [self assetsDestinationPath:bookName],strBookPath];                                      [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil];                                  }                              }                              else                              {                                  NSString *unUseBGFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/normal_images",                                                               [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUseBGFilePath error:nil];                                  NSString *unUseThumbNormalFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images/normal_images",                                                                        [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUseThumbNormalFilePath error:nil];                                  NSString *unUseThumbSelectedFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageBGAssets/thumb_images_deselected/normal_images",                                                                          [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUseThumbSelectedFilePath error:nil];                                  NSString *unUsePageAssetsFilePath = [@"" stringByAppendingFormat:@"%@/%@/BookPageAssets/normal_images",                                                                       [self assetsDestinationPath:bookName],strBookPath];                                  [[NSFileManager defaultManager] removeItemAtPath:unUsePageAssetsFilePath error:nil];                              }                          }                                                    NSString *macOSXFilePath = [@"" stringByAppendingFormat:@"%@/__MACOSX",[self assetsDestinationPath:bookName]];                          [[NSFileManager defaultManager] removeItemAtPath:macOSXFilePath error:nil];                      }                  }          }          else          {              [self showIAPFailMessage:bookName];              return;          }            [self cacheDicFileDeleteByNAme:tempPath.lastPathComponent];          dispatch_async(dispatch_get_main_queue(), ^{              [[MyScrollView sharedScrollView] stop_animation];          });      });  }    @end                

The errors we get in Xcode: META-INF: operation not permitted 713068: Operation not permitted

And we got we got this file path for ios 14. if (@available(iOS 14, *))

{  std::string text = [zipFolderPath UTF8String];  std::string textfind = "Caches/";  std::size_t found = text.find(textfind);  if (found != std::string::npos){  text.insert(found + textfind.size(),"StoreKit/");  zipFolderPath = [NSString stringWithUTF8String:text.c_str()];  }  }  

Any ideas why we can make iAP to work?

https://stackoverflow.com/questions/67293433/iap-issue-in-ios-14 April 28, 2021 at 11:38AM

没有评论:

发表评论