16.9 C
New York
Saturday, October 19, 2024

ios – Passing Information from AppDelegate.swift to Angular with Capacitor Plugin – “UNIMPLEMENTED” Error


I’ve an Angular software that I transformed into an iOS app utilizing Capacitor. I’m attempting to implement a function to retrieve well being knowledge utilizing Apple HealthKit and go that knowledge from the AppDelegate.swift file to my Angular app. I am utilizing a customized Capacitor plugin to do that, however I am encountering an error when organising the listener in Angular.

Right here’s what I’ve tried:

Well being Information Plugin (Swift):

import Capacitor

@objc(HealthDataPlugin)
public class HealthDataPlugin: CAPPlugin {

    static let shared = HealthDataPlugin()  // Singleton occasion

    @objc func sendHealthDataToAngular(knowledge: [String: Any]) {
        print("sendHealthDataToAngular referred to as with knowledge: (knowledge)")

        guard !knowledge.isEmpty else {
            print("Error: No knowledge supplied to sendHealthDataToAngular.")
            return
        }

        do {
            self.notifyListeners("healthDataReceived", knowledge: knowledge)
        } catch {
            print("Error: Did not notify listeners - (error.localizedDescription)")
        }
    }

    @objc func echo(_ name: CAPPluginCall) {
        let worth = name.getString("worth") ?? ""
        name.resolve([
            "value": value
        ])
    }
}

Name in AppDelegate.swift:

HealthDataPlugin.shared.sendHealthDataToAngular(knowledge: dataToSend)

Angular TypeScript (Listener Setup):

async setupHealthDataListener() {
    strive {
        console.log("Organising well being knowledge listener...");
        const eventListener = await (HealthDataPlugin as any).addListener('healthDataReceived', (eventData: any) => {
            console.log('Well being Information Obtained:', eventData);
        });

        console.log("Well being knowledge listener arrange efficiently:", eventListener);
    } catch (error) {
        console.error("Error organising well being knowledge listener:", error);
    }
}

Plugin Registration in Angular
(health-kit-plugin.ts):

import { registerPlugin } from '@capacitor/core';

const HealthDataPlugin = registerPlugin('HealthDataPlugin');

export default HealthDataPlugin;

capacitor.config.ts

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'app.rapidhealth',
  appName: 'Speedy Well being',
  webDir: './dist/speedy',
  server: {
    androidScheme: 'https'
  },
  plugins: {
    HealthDataPlugin: {},
  }
};

export default config;


Error Log from Xcode:

⚡️  [log] - Organising well being knowledge listener...
⚡️  [error] - Error organising well being knowledge listener: {"code":"UNIMPLEMENTED"}

Observe: I’ve tried working npx cap migrate which upgrading my capacitor model to 6.0.0 however this hasn’t solved my situation.

It looks like the listener isn’t being recognised or applied correctly. What could possibly be inflicting this “UNIMPLEMENTED” error, and the way can I accurately go the well being knowledge from AppDelegate.swift to my Angular app utilizing Capacitor?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles