Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
¿Cómo ejecutar el script JS que tiene importación desde npm-library en iPhone por Content View?

Tengo este código y node_modules en una carpeta compartida en el proyecto de código x. Tiene que mostrarme la clave de texto generada a partir de js-code. js-code funciona fuera de node.js, pero me muestra 'indefinido' en la vista de contenido. ¿Puedo importar módulos js en el proyecto de código x? ¿Funcionará en iPhone?

 // ContentView.swift // Shared import Foundation import SwiftUI import JavaScriptCore class Cube { func doJS(text: String) -> String? { let jsSource = "var testFunct = function test(message) { const NodeRSA = require('node-rsa'); const key = new NodeRSA(); var k = key.generateKeyPair(); var p = k.exportKey('pkcs1'); return p};" let context = JSContext() context?.evaluateScript(jsSource) let testFunction = context?.objectForKeyedSubscript("testFunct") return testFunction?.call(withArguments: [text]).toString() } } struct ContentView: View { var body: some View { Text(Cube().doJS(text: "Hello, world!") ?? "No result") .fontWeight(.black) .foregroundColor(Color.green) .padding() } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }

Mi código js:

 // npm install node-rsa // https://www.npmjs.com/package/node-rsa var testFunct = function test(message) { const NodeRSA = require('node-rsa'); const key = new NodeRSA(); var k = key.generateKeyPair(); var p = k.exportKey('pkcs1'); return p}; console.log(testFunct())

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!