Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Native Plugins in Tiny

Discussion in 'Project Tiny' started by sethfr, Dec 25, 2018.

  1. sethfr

    sethfr

    Joined:
    Dec 11, 2018
    Posts:
    2
    Hi all,

    I'm trying to get a native plugin working with Tiny and TypeScript. My Tiny project is in a WKWebView in my iOS app, and I want it to be able to call into some native code in my app. However, the Native Plugin docs don't mention TypeScript support at all.

    The docs do provide a JavaScript example using `@DllImport (DLLName)`, but when I try this in TypeScript, I get "TypeScriptError: Cannot find name 'DllImport'".

    Is there a way to call native plugins from TypeScript in a Tiny project, or is this not supported yet?

    Thanks in advance, and let me know if you need additional info!
     
    frankprogrammer likes this.
  2. abeisgreat

    abeisgreat

    Joined:
    Nov 21, 2016
    Posts:
    45
    I don't work on Tiny, but I've read all the docs several times and never seen any mention of native plugin support yet. If you need something quick, I assume your webview has some sort of binding where you can expose methods in the iOS app as JavaScript methods. If this is the case then you can expose your native calls in the webview then invoke them in your Typescript as all behaviors / systems can access the browser's Window object like a normal webpage. Ideally though, I'd wait for an official solution.
     
    sethfr likes this.
  3. sethfr

    sethfr

    Joined:
    Dec 11, 2018
    Posts:
    2
    Thanks, this worked great! I was able to leverage the `WKScriptMessageHandler` in iOS to intercept the JS. Didn't realize this would work.

    Definitely waiting on an official solution but just wanted to get a proof of concept working in the meantime. Thanks again!