ionic-team / CapacitorWatch

Build apps for watches with Capacitor
MIT License
43 stars 6 forks source link

No more than one component displaying, including the default components #42

Open MitchellPeck opened 4 months ago

MitchellPeck commented 4 months ago

When I run the app for the first time after build, it only shows 'Capacitor WATCH' - no button. and when i update the ui with my own items, it only displays the first item in the list.

Here's my .tsx:

const [t1, setT1] = useState("");

  async function uploadWatchUI1() {
    const watchUI = `Text("Capacitor n")
         Button("Add One", "inc")`;

    await Watch.updateWatchUI({ watchUI: watchUI });
  }

  async function updateData1() {
    var stateData = {
      variable: "data1",
    };

    await Watch.updateWatchData({ data: stateData });
  }

  async function updateData2() {
    var stateData = {
      variable: "data2",
    };

    await Watch.updateWatchData({ data: stateData });
  }

  useEffect(() => {
    Watch.addListener("runCommand", (data: { command: string }) => {
      console.log("PHONE got command - " + data.command);
      setT1(`Button was Pressed: ${data.command}`);
    });
  });

watchappApp.swift:

import SwiftUI
import WatchConnectivity
import iOS_capWatch_watch

@main
struct watchddgg_Watch_AppApp: App {
    var body: some Scene {
        WindowGroup {
            CapWatchContentView()
                .onAppear {
                    assert(WCSession.isSupported(), "This sample requires Watch Connectivity support!")
                    WCSession.default.delegate = WatchViewModel.shared
                    WCSession.default.activate()
                }
        }
    }
}

AppDelegate.swift:

import UIKit
import Capacitor
import WatchConnectivity
import CapacitorWatch
import CapacitorBackgroundRunner

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        assert(WCSession.isSupported(), "This sample requires Watch Connectivity support!")
        WCSession.default.delegate = CapWatchSessionDelegate.shared
        WCSession.default.activate()

        BackgroundRunnerPlugin.registerBackgroundTask()
        BackgroundRunnerPlugin.handleApplicationDidFinishLaunching(launchOptions: launchOptions)
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        // Called when the app was launched with a url. Feel free to add additional processing here,
        // but if you want the App API to support tracking app url opens, make sure to keep this call
        return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
    }

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        // Called when the app was launched with an activity, including Universal Links.
        // Feel free to add additional processing here, but if you want the App API to support
        // tracking app url opens, make sure to keep this call
        return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
    }
}

I have iOS-capWatch-watch added under Frameworks, Libraries, and Embedded Content:

Screenshot 2024-06-04 at 12 02 54 PM

Here's the error I get when I update the watch data:

Screenshot 2024-06-04 at 12 04 01 PM
MitchellPeck commented 4 months ago

Also, when I open Xcode, build for iOS, build for Watch, everything is fine. The problem is that if I need to build the iOS app again after making changes in my .tsx and rebuilding, I get an error saying that iOS-capWatch-watch has no export. This error doesn't happen consistently, and as luck would have it, it doesn't happen when I attempt to test it for this post...

Side note: updating data variables with updateWatchData works fine (for the one text UI component that I'm able to get to view) but I do get the same three errors:

Screenshot 2024-06-04 at 12 10 04 PM
MitchellPeck commented 4 months ago

I got the error for building iOS app after building the .tsx:

Screenshot 2024-06-04 at 1 13 19 PM