TrustKit icon indicating copy to clipboard operation
TrustKit copied to clipboard

Performing I/O on the main thread can cause slow launches.

Open crleonard opened this issue 8 months ago • 1 comments

Xcode is producing many warnings re performance could be slow.

TSKBackgroundReporter.m

The else block below.

else {
            // Get the vendor identifier
            _appVendorId = identifier_for_vendor();
            
            
            // We're not running unit tests - use a background session
            // AppleDoc (currently 10.3) state that multiple background sessions with the same
            // identifier should never be created, so ensure that cannot happen by creating
            // a unique ID per instance.
            NSString *backgroundSessionId = [NSString stringWithFormat:kTSKBackgroundSessionIdentifierFormat,
                                             _appBundleId, [[NSUUID UUID] UUIDString]];
            
            NSURLSessionConfiguration *backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:backgroundSessionId];
            backgroundConfiguration.discretionary = YES;
            backgroundConfiguration.sharedContainerIdentifier = sharedContainerIdentifier;
            
#if TARGET_OS_IPHONE
            // iOS-only settings
            // Do not wake up the App after completing the upload
            backgroundConfiguration.sessionSendsLaunchEvents = NO;
#if !TARGET_OS_TV && !TARGET_OS_WATCH
            // on iOS (but not tvOS or watchOS), enable multipath
            backgroundConfiguration.multipathServiceType = NSURLSessionMultipathServiceTypeHandover;
#endif
#endif
            
            // We have to use a delegate as background sessions can't use completion handlers
            _backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration
                                                               delegate:self
                                                          delegateQueue:nil];
        }

This is the below 2 lines.

  • NSURLSessionConfiguration *backgroundConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:backgroundSessionId]
  • _backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfiguration

crleonard avatar Apr 14 '25 17:04 crleonard

I don't see any issue in this code, it's just creating a NSURLSession, are you sure it's not a false positive? Could you please provide more information associated to the warning? Thank you.

ppamorim avatar May 13 '25 16:05 ppamorim