Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Type of expression is ambiguous without more context #123

Open
rustemmanafov opened this issue Feb 2, 2023 · 6 comments
Open

Error: Type of expression is ambiguous without more context #123

rustemmanafov opened this issue Feb 2, 2023 · 6 comments

Comments

@rustemmanafov
Copy link

func swizzleConnectionDidReceiveResponse(anyClass: AnyClass) {
//
// Have to explicitly tell the compiler which func
// because there are two different objc methods, but different argments
// It causes the bug: Ambiguous use of 'connection(
:didReceive:)'
//
let selector: Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)!)
as (NSURLConnectionDataDelegate) -> (NSURLConnection, URLResponse) -> Void)

    guard let method = class_getInstanceMethod(anyClass, selector),
        anyClass.instancesRespond(to: selector) else {
        return
    }

    typealias NewClosureType =  @convention(c) (AnyObject, Selector, AnyObject, AnyObject) -> Void
    let originalImp: IMP = method_getImplementation(method)
    let block: @convention(block) (AnyObject, AnyObject, AnyObject) -> Void = {[weak self] (me, connection, response) in

        // call the original
        let original: NewClosureType = unsafeBitCast(originalImp, to: NewClosureType.self)
        original(me, selector, connection, response)

        // Safe-check
        if let connection = connection as? NSURLConnection, let response = response as? URLResponse {
            self?.delegate?.injectorConnectionDidReceive(connection: connection, response: response)
        } else {
            assertionFailure("Could not get data from _swizzleConnectionDidReceiveResponse. It might causes due to the latest iOS changes. Please contact the author!")
        }
    }

    // Start method swizzling
    method_setImplementation(method, imp_implementationWithBlock(block))
}

func swizzleConnectionDidReceiveData(anyClass: AnyClass) {
//
// Have to explicitly tell the compiler which func
// because there are two different objc methods, but different argments
// It causes the bug: Ambiguous use of 'connection(
:didReceive:)'
//
let selector : Selector = #selector((NSURLConnectionDataDelegate.connection(_:didReceive:)!)
as (NSURLConnectionDataDelegate) -> (NSURLConnection, Data) -> Void)

    guard let method = class_getInstanceMethod(anyClass, selector),
        anyClass.instancesRespond(to: selector) else {
        return
    }

    typealias NewClosureType =  @convention(c) (AnyObject, Selector, AnyObject, AnyObject) -> Void
    let originalImp: IMP = method_getImplementation(method)
    let block: @convention(block) (AnyObject, AnyObject, AnyObject) -> Void = {[weak self] (me, connection, data) in

        // call the original
        let original: NewClosureType = unsafeBitCast(originalImp, to: NewClosureType.self)
        original(me, selector, connection, data)

        // Safe-check
        if let connection = connection as? NSURLConnection, let data = data as? Data {
            self?.delegate?.injectorConnectionDidReceive(connection: connection, data: data)
        } else {
            assertionFailure("Could not get data from _swizzleConnectionDidReceiveResponse. It might causes due to the latest iOS changes. Please contact the author!")
        }
    }

    // Start method swizzling
    method_setImplementation(method, imp_implementationWithBlock(block))
}
@rustemmanafov
Copy link
Author

Hi, Nghia please help me about this.

@NghiaTranUIT
Copy link
Member

Can you share with me some context:

  • What Atlantis version, Xcode, and iOS you're using?

@rustemmanafov
Copy link
Author

Xcode version 14.2
Min Deployment 13.0
Atlantis version pod 'atlantis-proxyman', '~> 1.4.3'

@rustemmanafov
Copy link
Author

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf-with-dsym'
config.build_settings['LD_NO_PIE'] = 'NO'
config.build_settings['CLANG_WARN_DOCUMENTATION_COMMENTS'] = 'NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end

@NghiaTranUIT
Copy link
Member

Please update the Atlantis to the latest version 1.20.0. You're using an 1 years ago version 👍

@rustemmanafov
Copy link
Author

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants