Using Capacitor v2 how do I send objects and parse them on swift/java side

framework: quasar
ui: vue 3
I was following the capacitor plugin guide but did not use the plugin creator so I made a Pluginname.swift and Pluginname.m I can do echo but making other functions that accept Objects like a json object yeilds nothing (doesnt seem like its even getting into the fuction or nothing is grabed by the function). is this because im missing the definitions.ts in the creator? ( I did register the other plugin methods by adding another CAP_PLUGIN_METHOD)

Some code would be helpful to see what you are doing.

The basics are documented here: iOS and Android.


import Foundation

import Capacitor

public class CWrapperPlugin: CAPPlugin{
    @objc func echo(_ call: CAPPluginCall){
        let value = call.getString("value") ?? ""
            "value": value
        // you can directly call sg functions from swift
    @objc func webEncodeObject(_ call: CAPPluginCall) {
        let Type = call.getObject("objectType")
            "objectType": Type




#import <Foundation/Foundation.h>

#import <Capacitor/Capacitor.h>

CAP_PLUGIN(CWrapperPlugin, "CWrapperPlugin",
           CAP_PLUGIN_METHOD(echo, CAPPluginReturnPromise);
           CAP_PLUGIN_METHOD(webEncodeObject, CAPPluginReturnPromise);

javascript vue 3 inside a setInterval

const reply = CWrapperPlugin.webEncodeObject({ objectType: object })

      reply.then((response) => {
        console.log(`this is the object reply: ${response.objectType}`)

What is object here?

object is a json object ( javascript inline object at this point but could be an object from the result of JSON.parse())
object contains ints floats and maybe some int arrays that are temporary


const object = {
Type: 1,
lat: 12.8988,
lon: 13.897786,
modes: [1,2,3,4,5]

could be 38 elements long

Oh right :slight_smile: I was reading that as the variable and not the type. I also didn’t know getObject existed on the Capacitor call object. I learned something new!

I don’t think this is valid. Android Studio for me at least says so.

    "objectType": Type

I think you want something like:

call.resolve(new JSObject().put("objectType", Type));

I think I might have a solution that I’m going to try I forgot set interval goes no matter what even if its not done

Thank you @twestrick for your help it didnt end up being the setInterval it was the inclusion of an array in the object that causes problems.

1 Like