Hi, I have created an internal only plugin, i.e. I don’t want it as a separate package. I know there are already SQLite plugins, but all the complications about the encryption registration has just put me off of them.
At any rate, ignoring the fact that it is an SQLite plugin, and I may want to do this for other things later, I don’t even get up to running the SQL on iOS, I have tried everything, including many what I think are outdated suggestions by various AI assistants.
I have the following the documentation here
I have the following…
My plugin code is
import Foundation
import Capacitor
@objc(SQLiteServicePlugin)
public class SQLiteServicePlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "SQLiteServicePlugin"
public let jsName: String = "SQLiteServicePlugin"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "get", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "getKeys", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "set", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "remove", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "defrag", returnType: CAPPluginReturnPromise)
]
private var service: SQLiteService?
public override func load() {
do {
NSLog("SQLiteServicePlugin load() called")
let lib = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!
let dbDir = lib.appendingPathComponent("MyAppDb", isDirectory: true)
service = try SQLiteService(folderURL: dbDir)
} catch {
NSLog("IOSSQLiteServicePlugin init error: \(error)")
}
}
@objc public func get(_ call: CAPPluginCall) {
guard let key = call.getString("key"), let svc = service else { call.reject("key required"); return }
do {
let value = try svc.get(key)
var ret: [String: Any] = [:]
if let v = value { ret["value"] = v }
call.resolve(ret)
} catch { call.reject(error.localizedDescription) }
}
However, the load() method is never called, and on the JS when I try and call one of the plugin methods, I get the exception SQLite set error: “SQLiteServicePlugin” plugin is not implemented on ios.
Also, on the JS side, my plugin does NOT appear in window.Capacitor.PluginHeaders, but it DOES appear in window.Capacitor.Plugins
My JS index.ts has
import { registerPlugin } from '@capacitor/core';
import { SQLitePlugin } from './definitions';
// eslint-disable-next-line @typescript-eslint/naming-convention
const SQLiteStorage = registerPlugin<SQLitePlugin>('SQLiteServicePlugin');
export { SQLiteStorage };
So the plugin is called SQLiteServicePlugin, matching what I have here…
All the other plugins work, just not mine, it is just not loaded.
The doco does mention…
Export to Capacitor
To make sure Capacitor can see your plugin, the plugin generator do two things: export your Swift class to Objective-C, and registers the plugin methods.
To export your Swift class to Objective-C, the plugin generator adds @objc(EchoPlugin) above your Swift class, and add @objc before the echo method.
but I did NOT use the plugin generator , as from what I can see, this was going to try and generate a separate package (which don’t want), so a bit confusing this is here.
Would anyone have any other ideas, anything else I can check/diagnose?



