Post

Replies

Boosts

Views

Activity

WatchConnectivity
Good morning, I come to you for a question: When I install my application on my iPhone for the first time, and I install the watch application from the native "Watch" application, the Watch Connectivity function does not work, I have to do the installation from Xcode to the watch for this function to work. Is this normal? if yes, the problem will not arise during a publication? I have the same problem when using watch and iPhone simulators, WatchConnectivity does not work. I am this error code in Xcode: -[WCSession handleIncomingUserInfoWithPairingID:]_block_invoke delegate (null) does not implement session:didReceiveUserInfo:, discarding incoming content Here is the code for the iPhone and the watch: In my iPhone app: import WatchConnectivity let userDefaultsDataVenantWatch = UserDefaults.standard class PhoneDataModel : NSObject, WCSessionDelegate, ObservableObject { static let shared = PhoneDataModel() let session = WCSession.default @Published var TableauSynchroIphoneVersWatch : [String:String] = ["0":"0"] @Published var dataWatchVersIphone: [String:String] = ["":""] override init() { super.init() if WCSession.isSupported() { session.delegate = self session.activate() } else { print("ERROR: Watch session not supported") } } func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { if let error = error { print("session activation failed with error: \(error.localizedDescription)") return } } func sessionDidBecomeInactive(_ session: WCSession) { session.activate() } func sessionDidDeactivate(_ session: WCSession) { session.activate() } func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any]) { guard let newCount = userInfo["TableauSynchroIphoneWatch"] as? [String:String] else { print("ERROR: unknown data received from Watch TableauSynchroIphoneWatch") return } DispatchQueue.main.async { print(newCount) } } } In my Watch app: import WatchConnectivity let userDefaultsDataVenantIphone = UserDefaults.standard var TableauVenantIphone:[String:String] = ["":""] class WatchDataModel : NSObject, WCSessionDelegate, ObservableObject { static let shared = WatchDataModel() let session = WCSession.default @Published var TableauSynchroIphoneWatch : [String:String] = ["0":"0"] override init() { super.init() if WCSession.isSupported() { session.delegate = self session.activate() } else { print("ERROR: Watch session not supported") } } func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { if let error = error { print("session activation failed with error: \(error.localizedDescription)") return } } func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any]) { guard let newCount = userInfo["TableauSynchroIphoneVersWatch"] as? [String:String] else { print("ERROR: unknown data received from Watch TableauSynchroIphoneWatch") return } DispatchQueue.main.async { print(newCount) } } } Thank for your answers !
2
0
635
Apr ’24
Convert View to Image for Share
Hello everyone, I need your help to convert my view in order to share it as an image: On one of my "VStack" views, I would like to convert this view into an Image and share it via the "ShareLink" function How can I convert a simple view to an Image? For example: ZStack { Rectangle() .fill(Color.blue.opacity(0.70)) .cornerRadius(16) VStack { Text("Share Text") } } Thank You for your help !
2
0
503
Apr ’24
Rotate Button
Hello World ! I need your help to perform a button rotation on my "VStack" view My "Foreach" loop defines a multitude of buttons for me. I would like it to rotate when I press a button. When I put a common variable, the code does not give me an error but all the buttons rotate. So I used a dictionary to make the buttons standalone but the code gave me an error. How can I make my buttons autonomous in the rotation while keeping my "foreach" loop? Thank you ! //Variable @State private var TableauRotationEffect:[String:Double] = ["":0.0] //Main Code in my view ForEach(1..<Int(nombreSerie)!+1, id: \.self) { numSerie in HStack(spacing: 20) { Text ("\(numSerie) // \(nombreSerie):").frame(width:200).font(.system(size: 13, weight: .regular)).foregroundColor(.gray).offset(x: 60, y: 0) Button { TableauRotationEffect["Ser:\(numSerie)"] = 90 print("Bouton anime 1 \(DateDebutSeance) // \(numeroExercice) // \(numeroSerie)") } label: { Label("Graph", systemImage: "chevron.right.circle") .labelStyle(.iconOnly) .imageScale(.large) .rotationEffect(.degrees(TableauRotationEffect["Ser:\(numSerie)"])) .padding() .animation(.easeInOut, value: showDetail) .frame(height:10) }.onAppear() { TableauRotationEffect["Ser:\(numSerie)"] = 0 } } }
1
0
403
Mar ’24
CoreMotion and movement WatchOS
Hello everyone, I'm coming to you because I'm having a little trouble finding the code to know the movement of the Apple Watch. I try to know exactly when the arm movement is up, down, left or right. I can define it thanks to “attitude.pitch” I can define it using "attitude", but it doesn't work correctly when the wrist is rotating at the same time as an arm movement. I no longer know how to move forward to know each movement. My code is as follows: (attitudeAvant11 is the attitude to the forward scan) (attitude11 is the attitude.pitch on the AppleWatch) Thank for your help func knowMove (attitude11:Double, attitudeAvant11:Double) -> (Sens2:String, attitudeAvant12:Double) { var attitude1 = attitude11 attitude1 = attitude1 * 100 let pourcentage = attitude1 - attitudeAvant if attitudeAvant != 0 { if pourcentage >= 0.5 { sensPrint = "Sens: Move down // ➡️\(pourcentage) ⬅️ // \(attitude1) // \(attitudeAvant)" sens1 = "1" } else { if pourcentage < -1.2 { sensPrint = "Sens: Move Up // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant)" sens1 = "2" } else { sensPrint = "Sens: No Move // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant)" sens1 = "0" } } } else { sensPrint = "Sens: No Move Initialisation // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant) " } let DateMaintenant = Date() let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS" let dateString = formatter.string(from: DateMaintenant) if sens1 != "Nul" { TableauAttitude["\(dateString)"] = "\(sens1)" //print(TableauAttitude) } attitudeAvant = attitude1 print("sensPrint: \(sensPrint)") return (sens1,attitudeAvant) }
0
0
662
Dec ’23
NavigationLink does not work
Hello, For my first watchOS app, I want use a navigationLink for switch to a new view, but the button does not work. Can you help me ? import SwiftUI struct ContentView: View { @State var timerVal = 1 @State var secondScreenShow = false @State private var selectedColor = "30s" var body: some View { VStack { NavigationLink ( destination: SecondView1() , isActive: $secondScreenShow, label: { Text("GO") }) } } } struct SecondView1: View { var body: some View { VStack { Text ("second view1") } } } struct ContentView_Preview: PreviewProvider { static var previews: some View { ContentView() } } Thank you
2
0
525
Nov ’23
Extension Timer Xcode
Hello,I'm coming to you because I have a problem when I try to start a timer with an integrated variable. This sends me a compilation error, I don't know how to send a variable in my timer function. I have two "swift" files and I want to keep two different files for my functions.my error:"Instance member 'AttaqueCanon' cannot be used on type 'ExtensionTimer'; did you mean to use a value of this type instead?"Thank for your help !In my "main.swift"let ExtensionTimer = Fichier2() gameTimerAttaqueCanon = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(ExtensionTimer.AttaqueCanon(tt:Sprite1)), userInfo: nil, repeats: true)in my "Fichier2.swift"import Foundation import SpriteKit class ExtensionTimer { @objcfunc AttaqueCanon(tt:SKSpriteNode) { let Canon1 = tt.childNode(withName: "Canon") } }
0
0
585
Jan ’20