ProxymanApp / atlantis

Capture HTTP/HTTPS, and Websocket from iOS app without proxy.
https://proxyman.io
Apache License 2.0
1.27k stars 95 forks source link

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

Open rustemmanafov opened 1 year ago

rustemmanafov commented 1 year ago

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 commented 1 year ago

Hi, Nghia please help me about this.

NghiaTranUIT commented 1 year ago

Can you share with me some context:

rustemmanafov commented 1 year ago

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

rustemmanafov commented 1 year ago

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 commented 1 year ago

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

rustemmanafov commented 1 year ago

Thanks a lot.