Thanks to visit codestin.com
Credit goes to github.com

Skip to content

willPerformHTTPRedirection swizzling crash #35

@willk37

Description

@willk37

Hi,

I'm trying to handle an HTTP redirect using URLSessionDataDelegate's urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler) function. But there seems to be an issue with conflicting implementations due to some swizzling in the AppSpector SDK. These conflicting implementations result in the app crashing.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtGC7Request22RequestSessionDelegateT__ _HTTP_swizzle_e67c49e9_URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]: unrecognized selector sent to instance 0x6000037761c0'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001804b910c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180092da8 objc_exception_throw + 72
	2   CoreFoundation                      0x00000001804cebf4 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
	3   CoreFoundation                      0x00000001804bd40c ___forwarding___ + 1268
	4   CoreFoundation                      0x00000001804bfb2c _CF_forwarding_prep_0 + 92
	5   AppSpectorSDK                       0x00000001065c359c __75+[ASNetworkObserver injectTaskWillPerformHTTPRedirectionIntoDelegateClass:]_block_invoke.291 + 32
	6   AppSpectorSDK                       0x00000001065bfc28 +[ASNetworkObserver sniffWithoutDuplicationForObject:selector:sniffingBlock:originalImplementationBlock:] + 184
	7   AppSpectorSDK                       0x00000001065c32e4 __75+[ASNetworkObserver injectTaskWillPerformHTTPRedirectionIntoDelegateClass:]_block_invoke_2 + 552
	8   CFNetwork                           0x000000018480cb28 __96-[__NSCFURLSessionDelegateWrapper task:willPerformHTTPRedirection:newRequest:completionHandler:]_block_invoke + 144
	9   libdispatch.dylib                   0x0000000105b6ccd8 _dispatch_call_block_and_release + 24
	10  libdispatch.dylib                   0x0000000105b6e5d0 _dispatch_client_callout + 16
	11  libdispatch.dylib                   0x0000000105b768b8 _dispatch_lane_serial_drain + 896
	12  libdispatch.dylib                   0x0000000105b77628 _dispatch_lane_invoke + 420
	13  libdispatch.dylib                   0x0000000105b842cc _dispatch_root_queue_drain_deferred_wlh + 324
	14  libdispatch.dylib                   0x0000000105b83838 _dispatch_workloop_worker_thread + 732
	15  libsystem_pthread.dylib             0x0000000104f5abcc _pthread_wqthread + 288
	16  libsystem_pthread.dylib             0x0000000104f5998c start_wqthread + 8
)
-[_TtGC7Request22RequestSessionDelegateT__ _HTTP_swizzle_e67c49e9_URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]: unrecognized selector sent to instance 0x6000037761c0
(
	0   CoreFoundation                      0x00000001804b910c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180092da8 objc_exception_throw + 72
	2   CoreFoundation                      0x00000001804cebf4 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
	3   CoreFoundation                      0x00000001804bd40c ___forwarding___ + 1268
	4   CoreFoundation                      0x00000001804bfb2c _CF_forwarding_prep_0 + 92
	5   AppSpectorSDK                       0x00000001065c359c __75+[ASNetworkObserver injectTaskWillPerformHTTPRedirectionIntoDelegateClass:]_block_invoke.291 + 32
	6   AppSpectorSDK                       0x00000001065bfc28 +[ASNetworkObserver sniffWithoutDuplicationForObject:selector:sniffingBlock:originalImplementationBlock:] + 184
	7   AppSpectorSDK                       0x00000001065c32e4 __75+[ASNetworkObserver injectTaskWillPerformHTTPRedirectionIntoDelegateClass:]_block_invoke_2 + 552
	8   CFNetwork                           0x000000018480cb28 __96-[__NSCFURLSessionDelegateWrapper task:willPerformHTTPRedirection:newRequest:completionHandler:]_block_invoke + 144
	9   libdispatch.dylib                   0x0000000105b6ccd8 _dispatch_call_block_and_release + 24
	10  libdispatch.dylib                   0x0000000105b6e5d0 _dispatch_client_callout + 16
	11  libdispatch.dylib                   0x0000000105b768b8 _dispatch_lane_serial_drain + 896
	12  libdispatch.dylib                   0x0000000105b77628 _dispatch_lane_invoke + 420
	13  libdispatch.dylib                   0x0000000105b842cc _dispatch_root_queue_drain_deferred_wlh + 324
	14  libdispatch.dylib                   0x0000000105b83838 _dispatch_workloop_worker_thread + 732
	15  libsystem_pthread.dylib             0x0000000104f5abcc _pthread_wqthread + 288
	16  libsystem_pthread.dylib             0x0000000104f5998c start_wqthread + 8
)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtGC7Request22RequestSessionDelegateT__ _HTTP_swizzle_e67c49e9_URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:]: unrecognized selector sent to instance 0x6000037761c0'
CoreSimulator 1010.10 - Device: iPhone 16 (C6DA581F-83EC-4544-9048-DE228C35270F) - Runtime: iOS 18.3 (22D8075) - DeviceType: iPhone 16

I'm curious if this is an issue with the SDK or is there a recommended solution for handling redirects while also still being able to use the AppSpector SDK?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions