Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Get Cordova plugin file to fully work in a web worker

I'm running an app with Cordova that has an extremely heavy optional file download. When run on the main thread iOS will shut down the app because it is running too long. In order to solve this, I decided to use web workers so it could run on a separate thread, (the error I was getting said to run the process on a separate thread). Since then I've had difficulties getting the plugins to work in a separate worker. Thus far I've been able to load Cordova and its plugin scripts and am able to call the modules but they are failing to call the native code because the native code relies on window.webkit.messageHandlers.cordova. As far as I can tell, when swift exposes the js methods it only exposes it to the main thread and there is no way to access the native code from the worker. Is there any other way to call native code from the worker that I'm missing?

(self as any).window = self;
(self as any).window.document = self;
(self as any).document = self;
(self as any).window.webkit = (window as any).webkit || {
  messageHandlers: {}
};
// import the scripts from their location in the www folder
const pathToCordovaPluginFile = "../plugins/cordova-plugin-file/www/";
importScripts(
  "../cordova.js",
  pathToCordovaPluginFile + "requestFileSystem.js",
  pathToCordovaPluginFile + "FileError.js",
  pathToCordovaPluginFile + "FileSystem.js",
  pathToCordovaPluginFile + "fileSystems.js",
  pathToCordovaPluginFile + "DirectoryEntry.js",
  pathToCordovaPluginFile + "Entry.js",
  pathToCordovaPluginFile + "DirectoryReader.js",
  pathToCordovaPluginFile + "Metadata.js"

  // pathToCordovaPluginFile + "File.js",
  // pathToCordovaPluginFile + "FileEntry.js",
  // pathToCordovaPluginFile + "FileReader.js",
  // pathToCordovaPluginFile + "FileWriter.js",
);

const getFileSystem = (PERSISTENT: number) => {
  try {
    const requestFileSystem: Window["requestFileSystem"] = cordova.require(
      "cordova-plugin-file.requestFileSystem"
    );
    return new Promise<FileSystem>((resolve, reject) =>
      requestFileSystem(PERSISTENT, 0, resolve, reject)
    );
  } catch {
    console.error("unable to request file system");
  }
};

(my code is technically in typescript not javascript)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

AFAIK web workers are NOT available on iOS WKWebView for iOS < 14

More information here and here

You should consider modifying the plugin to run your download on a sub native thread.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda