Skip to content

Return value through callback giving error. TypeError: window.HelloWorld.imageSource is not a function. #82

@MengdanCode

Description

@MengdanCode

Hi I'm trying to implement XWebView in my project by following the sample code. And I'm trying to pass a image file in base64 format from swift back to the webview and display it on html. I tried to follow the example given in #52 but I'm getting this error:

TypeError: window.HelloWorld.imageSource is not a function. (In 'window.HelloWorld.imageSource(function(result){ document.getElementById("img0").src = result;})', 'window.HelloWorld.imageSource' is undefined)

My swift code looks like this:

    func imageSource(callback: XWVScriptObject) {
        print(" PLARFORNN")
        callback.call(arguments: [strBase64], completionHandler: { result, error in
            print("Completed Javascript evaluation.")
            print("Result: \(result)")
            print("Error: \(error)")
        })
    }

And my javascript looks like this:

window.HelloWorld.imageSource(function(result){ 
	document.getElementById("img0").src = result;
});

I'm not too sure which part I did it wrongly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No 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