Skip to content

Purchases is blocking the main thread at app launch and at app return to foreground #3280

Description

@ronyfadel

Describe the bug
Purchases is calling "AAAttribution.attributionToken()" on the main queue. When the device is not connected to the internet, this call takes a while (is it doing a network call?).

  • I first worked around this issue by calling Purchases.shared.attribution.enableAdServicesAttributionTokenCollection() off the main thread.
  • however, Purchases is calling self.attribution.postAdServicesTokenOncePerInstallIfNeeded() when the app is entering foreground, blocking the main queue.
  1. Environment

    1. Platform: iOS
    2. SDK version: 4.27.1
    3. StoreKit version:
      • StoreKit 1
      • StoreKit 2 (enabled with usesStoreKit2IfAvailable(true))
    4. OS version: 15.6.1
    5. Xcode version:
    6. Device and/or simulator:
      • Device
      • Simulator
    7. Environment:
      • Sandbox
      • TestFight
      • Production
    8. How widespread is the issue. Percentage of devices affected.
  2. Steps to reproduce, with a description of expected vs. actual behavior

  • delete test app.
  • put device in Airplane mode.
  • start app, go to background, go to foreground.
  • Notice blockages.
  1. Other information
#0	0x00000001b7a474a0 in mach_msg_trap ()
#1	0x00000001b7a47ae4 in mach_msg ()
#2	0x000000010540305c in _dispatch_mach_send_and_wait_for_reply ()
#3	0x00000001054033e4 in dispatch_mach_send_with_result_and_wait_for_reply ()
#4	0x00000001f1254f0c in xpc_connection_send_message_with_reply_sync ()
#5	0x00000001822b0c4c in __NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__ ()
#6	0x00000001822b6d1c in -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] ()
#7	0x00000001822ca514 in -[NSXPCConnection _sendSelector:withProxy:arg1:] ()
#8	0x000000018229bdf0 in _NSXPCDistantObjectSimpleMessageSend1 ()
#9	0x00000001f1e58060 in ___lldb_unnamed_symbol38 ()
#10	0x000000010176ee28 in AttributionFetcher.adServicesToken.getter at /Users/ronyfadel/Library/Developer/Xcode/DerivedData/VidCap-bwtrrsrmwbcpyyczvixlxumnkjsc/SourcePackages/checkouts/purchases-ios/Sources/Attribution/AttributionFetcher.swift:99
#11	0x0000000101773dd8 in AttributionPoster.adServicesTokenToPostIfNeeded.getter at /Users/ronyfadel/Library/Developer/Xcode/DerivedData/VidCap-bwtrrsrmwbcpyyczvixlxumnkjsc/SourcePackages/checkouts/purchases-ios/Sources/Attribution/AttributionPoster.swift:148
#12	0x0000000101773c90 in AttributionPoster.postAdServicesTokenOncePerInstallIfNeeded() at /Users/ronyfadel/Library/Developer/Xcode/DerivedData/VidCap-bwtrrsrmwbcpyyczvixlxumnkjsc/SourcePackages/checkouts/purchases-ios/Sources/Attribution/AttributionPoster.swift:131
#13	0x000000010194d838 in Attribution.postAdServicesTokenOncePerInstallIfNeeded() at /Users/ronyfadel/Library/Developer/Xcode/DerivedData/VidCap-bwtrrsrmwbcpyyczvixlxumnkjsc/SourcePackages/checkouts/purchases-ios/Sources/Purchasing/Purchases/Attribution.swift:72
#14	0x00000001019638b8 in Purchases.applicationWillEnterForeground() at /Users/ronyfadel/Library/Developer/Xcode/DerivedData/VidCap-bwtrrsrmwbcpyyczvixlxumnkjsc/SourcePackages/checkouts/purchases-ios/Sources/Purchasing/Purchases/Purchases.swift:1504
#15	0x0000000101963bd0 in @objc Purchases.applicationWillEnterForeground() ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions