|
| 1 | +--- |
| 2 | +title: Auto-Update SDK |
| 3 | +sidebar_title: Auto-Update SDK |
| 4 | +sidebar_order: 10 |
| 5 | +description: Enable automatic update checks and installations for internal iOS builds using the Sentry Auto-Update SDK. |
| 6 | +--- |
| 7 | + |
| 8 | +<Include name="feature-available-for-user-group-early-adopter" /> |
| 9 | + |
| 10 | +<Alert level="warning"> |
| 11 | + |
| 12 | +The Auto-Update SDK is designed for **internal builds only** and should never be used in production builds distributed through the App Store. |
| 13 | + |
| 14 | +</Alert> |
| 15 | + |
| 16 | +The Sentry Auto-Update SDK enables your internal iOS builds to automatically check for and install newer versions distributed through Sentry's Build Distribution. This is particularly useful for distributing nightly, alpha, or beta builds to your internal teams. It is not required to use the Sentry crash reporting SDK to use the iOS Auto-Update SDK. |
| 17 | + |
| 18 | +## Pre-requisites |
| 19 | + |
| 20 | +The SDK can only be installed using Swift Package Manager. |
| 21 | + |
| 22 | +You'll also need an [internal integration token](#create-an-integration-token) with Build Distribution permissions. |
| 23 | + |
| 24 | +<Include name="build-distribution/create-integration-token" /> |
| 25 | + |
| 26 | +## Installation |
| 27 | + |
| 28 | +Add a dependency on the `SentryDistribution` target contained in the sentry-cocoa package (https://github.com/getsentry/sentry-cocoa) |
| 29 | + |
| 30 | +```swift {filename:Package.swift} |
| 31 | +.package(url: "https://github.com/getsentry/sentry-cocoa", from: "{{@inject packages.version('sentry.cocoa') }}"), |
| 32 | + |
| 33 | +.target(name: "MyTarget", dependencies: ["SentryDistribution"]), |
| 34 | +``` |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +Use the SDK by calling `Updater.checkForUpdate(params: )`. In addition to the access token, provide your Sentry org and project slug in the CheckForUpdateParams. For example: |
| 39 | + |
| 40 | +```swift {filename:MyView.swift} |
| 41 | +import SentryDistribution |
| 42 | +import SwiftUI |
| 43 | + |
| 44 | +struct MyView: View { |
| 45 | + var body: some View { |
| 46 | + Button("Check For Update") { |
| 47 | + UpdateUtil.checkForUpdates() |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +enum UpdateUtil { |
| 53 | + static func checkForUpdates() { |
| 54 | + let params = CheckForUpdateParams( |
| 55 | + accessToken: "MY_TOKEN", |
| 56 | + organization: "MY_ORGANIZATION", |
| 57 | + project: "MY_PROJECT") |
| 58 | + Updater.checkForUpdate(params: params) { result in |
| 59 | + handleUpdateResult(result: result) |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + static func handleUpdateResult(result: Result<UpdateCheckResponse, Error>) { |
| 64 | + guard case let .success(releaseInfo) = result else { |
| 65 | + if case let .failure(error) = result { |
| 66 | + print("Error checking for update: \(error)") |
| 67 | + } |
| 68 | + return |
| 69 | + } |
| 70 | + |
| 71 | + guard let releaseInfo = releaseInfo.update else { |
| 72 | + print("Already up to date") |
| 73 | + return |
| 74 | + } |
| 75 | + |
| 76 | + guard let url = Updater.buildUrlForInstall(releaseInfo.downloadUrl) else { |
| 77 | + return |
| 78 | + } |
| 79 | + DispatchQueue.main.async { |
| 80 | + Updater.install(url: url) |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +## Security Considerations |
| 87 | + |
| 88 | +- **Internal Use Only**: Never ship the auto-update SDK in production builds destined for public app stores |
| 89 | +- **Token Security**: The distribution token is embedded in the app and can be extracted by reverse engineering. Use tokens with only the distribution read permission which is the minimum required permission for the auto-update SDK. |
| 90 | + |
| 91 | + |
0 commit comments