Coder Social home page Coder Social logo

Comments (3)

newyankeecodeshop avatar newyankeecodeshop commented on July 26, 2024

There isn't a built-in syntax for doing that. GAJavaScript only allows invoking existing ObjC objects, via "GAJavaScript.performSelector(..)" or by invoking a block set on a JS object using [GAScriptObject setFunction:forKey:].

Can you provide more of an idea of what you want to accomplish?

from gajavascript.

lucamaraschi avatar lucamaraschi commented on July 26, 2024

performSelector executes a void method (selector)...

what I'm trying to accomplish are the 2 following scenarios:

  1. Create an instance of an existing ObjC object from a javascript script: for example create an instance of object foo and call a method on it.
  2. call a method in the ObjC runtime and get a result back: not only performing a void selector but executing a real invocation and return its result.

from gajavascript.

newyankeecodeshop avatar newyankeecodeshop commented on July 26, 2024

Those have both been hard to accomplish because the mechanism to invoke Objective-C from JS uses a UIWebViewDelegate callback that is invoked as a side-effect of URL navigation (e.g. location.replace or form.submit()). I believe I found a way to invoke Objective-C synchronously, using an iframe element and removing/adding it to the DOM. However, I haven't needed this and I'm not sure how reliable it is.

An alternative would be to have performSelector() take a callback function that would receive the return value of the Objective-C call. It's something that I haven't gotten around to yet. I might have some time to get to it in the next week or so, but if not, perhaps you or someone in the community could?

from gajavascript.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.