StravaKit is a powerful and versatile library designed to seamlessly integrate Strava functionality into iOS applications. With StravaKit, developers can easily incorporate features like authentication, activity tracking, and leaderboards, enhancing the user experience and providing a rich fitness-tracking platform.
Features
- Authentication: Easily integrate Strava OAuth2 authentication into your app.
- Activity Tracking: Track and monitor user activities, including distance, duration, and elevation.
- Leaderboards: Enable users to compete against each other by implementing leaderboards.
- Segment Analysis: Access detailed analysis and statistics for segments, including performance metrics and leaderboards.
- Route Planning: Allow users to discover, create, and save routes.
- Privacy Controls: Implement privacy settings to control data sharing.
- Club Integration: Integrate with Strava clubs and manage club-related activities.
- Workout Data: Retrieve and analyze workout-related data, such as heart rate, power, and cadence.
Getting Started
To integrate StravaKit into your iOS application, follow these steps:
- Install StravaKit via the Cocoapods dependency manager by adding the following line to your Podfile:
“`ruby
pod ‘StravaKit’
“`
- Run `pod install` to install the StravaKit library and its dependencies.
- Import StravaKit into your project:
“`swift
import StravaKit
“`
- Before using the library, make sure to register your application with Strava and obtain an API client ID and secret. This is necessary to authenticate and access Strava API resources.
- Set up the authentication process by following the StravaKit documentation that includes OAuth2 flow and obtaining access tokens.
- You are now ready to leverage the power of StravaKit to enhance your application’s functionality!
Usage
1. Authentication
To authenticate Strava users in your app, follow these steps:
- Configure your app to redirect to an authentication URL:
“`swift
StravaAuthorization.shared.redirectURL = URL(string: “Your-Redirect-URL”)
“`
- Initiate the authentication process:
“`swift
StravaAuthorization.shared.authenticate()
“`
- Handle the response in your app delegate:
“`swift
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
StravaAuthorization.shared.handleAuthorizationResponse(url: url)
return true
}
“`
2. Activity Tracking
Use StravaKit to track user activities, including distance, duration, and elevation:
- Retrieve the authenticated user’s activities:
“`swift
StravaActivityAPI.listAuthenticatedAthleteActivities { activities, _ in
if let activities = activities {
// Handle retrieved activities
} else {
// Handle error
}
}
“`
- Create a new activity:
“`swift
let activity = StravaActivity(name: “Activity Name”,
type: .ride,
startDate: Date(),
duration: 3600, // in seconds
distance: 15000, // in meters
elevationGain: 500, // in meters)
StravaActivityAPI.createActivity(activity) { newActivity, _ in
if let activity = newActivity {
// Handle created activity
} else {
// Handle error
}
}
“`
3. Leaderboards
Enable users to compete against each other by implementing leaderboards:
- Retrieve segment leaderboards:
“`swift
StravaSegmentAPI.retrieveSegmentLeaderboards(segmentId: 1234) { leaderboards, _ in
if let leaderboards = leaderboards {
// Handle retrieved leaderboards
} else {
// Handle error
}
}
“`
- Filter segment leaderboards by different parameters, such as age group or weight class.
4. Segment Analysis
Access detailed analysis and statistics for segments, including performance metrics and leaderboards:
- Retrieve segment details:
“`swift
StravaSegmentAPI.retrieveSegment(segmentId: 1234) { segment, _ in
if let segment = segment {
// Handle retrieved segment
} else {
// Handle error
}
}
“`
- Access segment effort leaderboards:
“`swift
StravaSegmentAPI.retrieveSegmentEffortLeaderboards(segmentId: 1234) { leaderboards, _ in
if let leaderboards = leaderboards {
// Handle retrieved leaderboards
} else {
// Handle error
}
}
“`
Documentation
For detailed information about StravaKit and its APIs, refer to the official StravaKit documentation.
Support
If you have any questions, issues, or feature requests, you can reach out to our support forum for assistance.
License
StravaKit is released under the MIT License.