ionic-team / CapacitorWatch

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

Cannot find 'CapWatchContentView' in scope #35

Open jacobglowdev opened 8 months ago

jacobglowdev commented 8 months ago

I've followed the documentation up to step 7, my watchOS.swift file currently looks like this:

import SwiftUI
import WatchConnectivity

@main
struct watchOS_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()
                }
        }
    }
}

I'm receiving the error: Cannot find 'CapWatchContentView' in scope

I can confirm the capacitor/watch plugin exists in my package.json file. The only other thing I can think of that may (or may not) be relevant is that after I added the Capacitor Watch Swift Package from node modules, its name reads as iOS-capWatch-watch instead of CapWatch-Watch-SPM.

I have tried adding import CapacitorWatch above the @main statement, but this also throws the No such module 'CapacitorWatch' error.

giralte-ionic commented 8 months ago

You need to import CapactiorWatch here as well

jacobglowdev commented 8 months ago

You need to import CapactiorWatch here as well

Apologies - I have updated my comment to highlight that I have tried this already.

jacobglowdev commented 8 months ago

Additional Information - after adding the package dependency, I quit xcode and tried to build it again with npm run ios, however it now fails with the following message:

RuntimeError - PBXProject attempted to initialize an object with unknown ISA XCLocalSwiftPackageReference from attributes: {"isa"=>"XCLocalSwiftPackageReference", "relativePath"=>"../../node_modules/@capacitor/watch/CapWatch-Watch-SPM"}

So something has gone wrong with the adding the package dependency?

giralte-ionic commented 8 months ago

just to confirm, are you using Xcode 15?

jacobglowdev commented 8 months ago

just to confirm, are you using Xcode 15?

Yep, Xcode 15

giralte-ionic commented 8 months ago

so I just tried running the install instructions on a new cap project and encountered the same thing you have. This is happening because for some reason Xcode is now assuming everything inside an SPM is 'private' and that causes the things there to be out of scope. I'll need to make an update to the package to fix this.

jacobglowdev commented 8 months ago

Thanks - is there an estimated timeframe for this fix?

giralte-ionic commented 8 months ago

I'm hoping to get to it this week

jacobglowdev commented 7 months ago

Is there any update on this?

benmarsh commented 7 months ago

Appreciate this may be lower down on the list of priorities but we're also looking into adding Apple Watch functionality to our Capacitor app and this looks to be the ideal solution. Would be great to get an ETA if at all possible. Thanks šŸ™

jacobglowdev commented 7 months ago

I'm hoping to get to it this week

I understand if this isn't a priority ticket for you guys, but are you able to advise a rough timeframe for this fix? Just so I can make a decision on whether to look into alternative approaches.

giralte-ionic commented 7 months ago

I should have a little time this week. So maybe this week, but I'm not promising anything

giralte-ionic commented 6 months ago

Ok give version 0.1.11 a spin. I've also updated the README a little, in Step 6 of creating the watch app you need to add import iOS_capWatch_watch in addition to the other changes. Let me know if this gets you up and running.

JensUweB commented 6 months ago

@giralte-ionic I tested your fix including the changes in step 6 in our Enterprise App and tried running ionic cap build ios. Sadly, the command failed basically with the same error as before.

> capacitor sync ios
[capacitor] āœ” Copying web assets from dist to ios/App/App/public in 117.81ms
[capacitor] āœ” Creating capacitor.config.json in ios/App/App in 2.36ms
[capacitor] āœ” copy ios in 168.15ms
[capacitor] āœ” Updating iOS plugins in 10.15ms
[capacitor] [info] Found 8 Capacitor plugins for ios:
[capacitor]        @capacitor-community/screen-brightness@5.0.0
[capacitor]        @capacitor/app@5.0.6
[capacitor]        @capacitor/camera@5.0.8
[capacitor]        @capacitor/haptics@5.0.6
[capacitor]        @capacitor/keyboard@5.0.7
[capacitor]        @capacitor/share@5.0.6
[capacitor]        @capacitor/splash-screen@5.0.7
[capacitor]        @capacitor/watch@0.1.11
[capacitor] āœ– Updating iOS native dependencies with pod install - failed!
[capacitor] āœ– update ios - failed!
// ...
RuntimeError - `PBXProject` attempted to initialize an object with unknown ISA `XCLocalSwiftPackageReference` from attributes: `{"isa"=>"XCLocalSwiftPackageReference", "relativePath"=>"../../node_modules/@capacitor/watch/CapWatch-Watch-SPM"}`
[capacitor]         If this ISA was generated by Xcode please file an issue: https://github.com/CocoaPods/Xcodeproj/issues/new
giralte-ionic commented 6 months ago

I'm sorry the cocoapod failed to publish. I have corrected this. Please try again.

JensUweB commented 6 months ago

The error still persists with version @capacitor/watch@0.1.12 for me. Stuff I tried:

giralte-ionic commented 6 months ago

try removing your Podfile.lock file and run npx cap sync from your project root. I just tried an initial project setup and things worked correctly.

JensUweB commented 6 months ago

I'm sorry to bother you again, but I can't get it to work. I set up a completely new App with Ionic Capacitor & React, installed capacitor watch, executed the steps in your Readme and run into the error again.

You can check out this repo if you like for reproduction. I'm using XCode 15.3 & MacOS Sonoma 14.4. Maybe this is an issue with the latest XCode version?

A coworker of mine could reproduce the issue with that repo above & our production app as well.

giralte-ionic commented 6 months ago

So I pulled your repo down and there are two problems:

1) In your watch app target, add the iOS-capWatch-watch framework to the 'Frameworks, Libraries and Embedded content' section. When you added the watch spm to the project, you didn't select the watch app as the target

2) In AppDelegate.swift, you typo'd import CapacitorWatch:

import CapacitorWatch
//import CapactiorWatch 

Fixing these two things gets me a successful build.

giralte-ionic commented 6 months ago

@JensUweB has this issue been resolved?