Challenge View
Exciting Challenges: Drive Engagement and Motivation.
- Fun and Competitive: Quick challenges with leaderboards for friendly competition
- Boost Activity: Keep fitness exciting and rewarding for users
- Easy Integration: Add dynamic challenges effortlessly to your app
You can find exercises in our exercise library, or create your own exercises in our admin portal.
Options (details in Challenge mode): exercise, countdown (challenge length in seconds), reps (a rep target instead of a timer) and showLeaderboard. The rest before the challenge lasts exactly restDuration seconds when you send it. Otherwise it is the exercise's own rest length plus time for the greeting; an exercise without one gets 10 seconds, lengthened to fit the greeting and rest speech unless you send dynamicRestEnabled: false. includePoseData streams real-time motion data as in the Workout View.
If the user goes back into the exercise screen (for example with Android back), the challenge starts a new run with fresh reps and its own workout_started instead of adding to the previous run.
Events: challenge_started on Start, the workout events during the run, workout_overview and challenge_completed on the results screen, then workout_completed and challenge_exit when the user leaves it, after which the challenge screen shows again. Back from the challenge screen posts exit_kinestex. See Challenge events.
1kinestex.createChallengeView(
2 exercise: challengeExercise, // exercise name or ID
3 duration: 100, // duration of challenge in seconds (sent as countdown)
4 showLeaderboard: true, // showLeaderboard prompts a user to enter a challenge at the end (true by default)
5 user: nil, // Optionally pass user details
6 style: IStyle(style: "dark"), // "dark" or "light" theme
7 isLoading: $isLoading,
8 onMessageReceived: { message in
9 switch message {
10 case .exit_kinestex(let data):
11 showKinesteX = false // dismiss the view
12 default:
13 print("Received \(message)")
14 break
15 }
16 }
17)1import SwiftUI
2import KinesteXAIKit
3
4struct ChallengeIntegrationView: View {
5 @State private var showKinesteX = false
6 @State private var isLoading = false
7
8 // Initialize KinesteXAIKit
9 // Replace with your KinesteX credentials
10 let kinesteXKit = KinesteXAIKit(
11 apiKey: "YOUR API KEY",
12 companyName: "YOUR COMPANY NAME",
13 userId: "YOUR USER ID"
14 )
15
16 // Challenge parameters
17 let challengeExercise = "Squats"
18 let challengeDuration = 100 // Duration in seconds
19 let showLeaderboardAfterChallenge = true
20
21 var body: some View {
22 VStack {
23 Text("KinesteX Challenge Integration")
24 .font(.title)
25 .padding()
26
27 Spacer()
28
29 Button(action: {
30 showKinesteX.toggle()
31 }) {
32 Text("Start \(challengeExercise) Challenge (\(challengeDuration)s)")
33 .font(.title3)
34 .foregroundColor(.white)
35 .bold()
36 .padding()
37 .frame(maxWidth: .infinity)
38 .background(Color.red.cornerRadius(10))
39 .padding(.horizontal)
40 }
41 .padding()
42
43 Spacer()
44 }
45 .fullScreenCover(isPresented: $showKinesteX) {
46 kinesteXKit.createChallengeView(
47 exercise: challengeExercise,
48 duration: challengeDuration,
49 showLeaderboard: showLeaderboardAfterChallenge,
50 user: nil,
51 style: IStyle(style: "dark"),
52 isLoading: $isLoading,
53 onMessageReceived: { message in
54 switch message {
55 case .exit_kinestex(_):
56 showKinesteX = false
57 default:
58 print("Message received: \(message)")
59 }
60 }
61 )
62 }
63 }
64}
65
66#Preview {
67 ChallengeIntegrationView()
68}
