-1

I am making an app iPhone and Watch app. The main purpose of the application is to add Apple Watch watchface when the button is pressed. In the iPhone application, I set 10 watches from the iPhone's own official watch application and put different types of watches in my project in .watchface file format. When I click the button and want to share the watchface apple watch, the iPhone official watch application gives the following error: This Watch is not available with your current version of watchOS

ContentView (iPhone side code)

import SwiftUI
import ClockKit

struct ContentView: View {
  @EnvironmentObject private var session: Session

  var body: some View {
    VStack {
      Image("FacePreview")

      if session.showFaceSharing {
        Button {
          Task { await sendWatchFace() }
        } label: {
          Image("ShareButton")
        }
      } else {
        Text("Unable to share watch face")
          .font(.title)

        Text("Please pair an Apple Watch first")
          .font(.title3)
      }
    }
  }

  func sendWatchFace() async {
    guard let url = Bundle.main.url(
      forResource: "FaceToShare",
      withExtension: "watchface"
    ) else {
      fatalError("You didn't include the watchface file in the bundle.")
    }

    let library = CLKWatchFaceLibrary()

    do {
      try await library.addWatchFace(at: url)
    } catch {
      print(error.localizedDescription)
    }
  }
}

Session (iPhone side code)

import SwiftUI
import WatchConnectivity

final class Session: NSObject, ObservableObject {
  static let shared = Session()

  @MainActor
  @Published
  var showFaceSharing = false

  private func updateFaceSharing(_ session: WCSession) {
    let activated = session.activationState == .activated
    let paired = session.isPaired

    Task { @MainActor in
      self.showFaceSharing = activated && paired
    }
  }

  override private init() {
    super.init()

    guard WCSession.isSupported() else {
      return
    }

    WCSession.default.delegate = self
    WCSession.default.activate()
  }
}

extension Session: WCSessionDelegate {
  func sessionDidBecomeInactive(_ session: WCSession) {
    updateFaceSharing(session)
  }

  func sessionDidDeactivate(_ session: WCSession) {
    WCSession.default.activate()
  }

  func session(
    _ session: WCSession,
    activationDidCompleteWith activationState: WCSessionActivationState,
    error: Error?
  ) {
    updateFaceSharing(session)
  }
  
  func sessionWatchStateDidChange(_ session: WCSession) {
    updateFaceSharing(session)
  }
}

I didn't write any code in the watch part, it stays as it was originally created because I think my problem is between my app and the official watch app.

I paired iPhone and Watch in the app simulator. I tried different versions of the simulator and ran it, the result was the same. (iPhone - 16.4 __ Watch - 9.4) - (iPhone - 15.4 __ Watch - 8.5)

I tried different watch faces, I exported the active watches in the official watch application and added them to my project, the result did not change.

I don't think the question is about the code, but because the project is very simple, I shared the relevant codes.

Am i making a mistake somewhere?

Xcode and simulator are in the latest version.

CoderBatu
  • 1
  • 1

0 Answers0