framework: quasar
ui: vue 3
Issue:
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.
swift:
import Foundation
import Capacitor
@objc(CWrapperPlugin)
public class CWrapperPlugin: CAPPlugin{
@objc func echo(_ call: CAPPluginCall){
let value = call.getString("value") ?? ""
call.resolve([
"value": value
])
// you can directly call sg functions from swift
}
@objc func webEncodeObject(_ call: CAPPluginCall) {
let Type = call.getObject("objectType")
call.resolve([
"objectType": Type
])
}
}
.m
#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
ex.
const object = {
Type: 1,
lat: 12.8988,
lon: 13.897786,
modes: [1,2,3,4,5]
}
could be 38 elements long
Oh right 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.
call.resolve([
"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.