### Configure Crowdin SDK via Info.plist (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/setup Start the Crowdin SDK using the start() method in your AppDelegate for Swift projects configured via Info.plist. ```swift CrowdinSDK.start() ``` -------------------------------- ### Configure and Start Crowdin SDK in Swift Source: https://crowdin.github.io/mobile-sdk-ios/setup Configure the Crowdin SDK with your distribution hash and source language, then start the SDK. The completion block is executed once the SDK is ready. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{distribution_hash}", sourceLanguage: "{source_language}") let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: { // SDK is ready to use, put code to change language, etc. here }) ``` -------------------------------- ### Configure and Start Crowdin SDK in Objective-C Source: https://crowdin.github.io/mobile-sdk-ios/setup Configure the Crowdin SDK with your distribution hash and source language, then start the SDK. The completion block is executed once the SDK is ready. ```objectivec CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@""]; CrowdinSDKConfig *config = [[[CrowdinSDKConfig config] withCrowdinProviderConfig:crowdinProviderConfig]]; [CrowdinSDK startWithConfig:config completion:^{ // SDK is ready to use, put code to change language, etc. here }]; ``` -------------------------------- ### Configure Crowdin SDK via Info.plist (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/setup Start the Crowdin SDK using the start method in your AppDelegate for Objective-C projects configured via Info.plist. ```objectivec [CrowdinSDK start] ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Run this command after updating your Podfile to install the necessary dependencies. ```bash pod install ``` -------------------------------- ### Install CrowdinSDK with Settings Subspec Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To enable the settings feature, add the 'CrowdinSDK/Settings' pod to your Podfile. This allows enabling/disabling various SDK features. ```ruby pod 'CrowdinSDK/Settings' ``` -------------------------------- ### Install Crowdin SDK with Controls Pods Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/sdk-controls Add these pods to your Podfile to include the Crowdin SDK and its features, including the SDK Controls widget. ```ruby use_frameworks! target 'your-app' do pod 'CrowdinSDK' pod 'CrowdinSDK/LoginFeature' # Required for Screenshots and Real-Time Preview pod 'CrowdinSDK/Screenshots' # Required for Screenshots pod 'CrowdinSDK/RealtimeUpdate' # Required for Real-Time Preview pod 'CrowdinSDK/Settings' # Add SDK Controls widget end ``` -------------------------------- ### Install CrowdinSDK with RealtimeUpdate Subspec Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To enable the Real-Time Preview feature, add the 'CrowdinSDK/RealtimeUpdate' pod to your Podfile. ```ruby pod 'CrowdinSDK/RealtimeUpdate' ``` -------------------------------- ### Install CrowdinSDK with Screenshots Subspec Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To enable the Screenshots feature, add the 'CrowdinSDK/Screenshots' pod to your Podfile. ```ruby pod 'CrowdinSDK/Screenshots' ``` -------------------------------- ### Install CrowdinSDK with Login Subspec Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To enable login functionality, add the 'CrowdinSDK/Login' pod to your Podfile. This requires setting up a CrowdinLoginConfig object. ```ruby pod 'CrowdinSDK/Login' ``` -------------------------------- ### Complete Example: Automated Screenshot Test Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation A full XCUI test case demonstrating how to configure the Crowdin SDK for UI testing, launch the app with the testing argument, and capture a screenshot. ```swift import XCTest import CrowdinSDK final class ScreenshotsUITests: XCTestCase { private static let distributionHash = "{distribution_hash}" private static let sourceLanguage = "{source_language}" private static let accessToken = "{access_token}" override class func setUp() { // Configure SDK for UI Testing let crowdinProviderConfig = CrowdinProviderConfig(hashString: Self.distributionHash, sourceLanguage: Self.sourceLanguage) let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(accessToken: Self.accessToken) .with(screenshotsEnabled: true) CrowdinSDK.startWithConfigSync(crowdinSDKConfig) } override class func tearDown() { CrowdinSDK.stop() CrowdinSDK.deintegrate() } @MainActor func testScreenshots() throws { let app = XCUIApplication() // Recommended: Add launch argument to enable UI testing mode app.launchArguments = ["CROWDIN_UI_TESTING"] app.launch() // Capture main screen let result = CrowdinSDK.captureOrUpdateScreenshotSync( name: "MAIN_SCREEN", image: XCUIScreen.main.screenshot().image, application: app ) XCTAssertNil(result.error) // Verify no errors occurred } } ``` -------------------------------- ### Install CrowdinSDK with IntervalUpdate Subspec Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To enable updating localization strings at defined time intervals, add the 'CrowdinSDK/IntervalUpdate' pod to your Podfile. ```ruby pod 'CrowdinSDK/IntervalUpdate' ``` -------------------------------- ### Install CrowdinSDK with RefreshLocalization Subspec Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To enable functionality to force refresh localization strings, add the 'CrowdinSDK/RefreshLocalization' pod to your Podfile. ```ruby pod 'CrowdinSDK/RefreshLocalization' ``` -------------------------------- ### Import Crowdin SDK (Swift Package Manager) Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Import the Crowdin SDK and its screenshot module in your UI tests source files after installation via Swift Package Manager. ```swift import CrowdinSDK import CrowdinTestScreenshots ``` -------------------------------- ### Import Crowdin SDK (CocoaPods) Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Import the Crowdin SDK in your UI tests source files after installation via CocoaPods. ```swift import CrowdinSDK ``` -------------------------------- ### Add Screenshots to Podfile Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots Configure your Podfile to include the necessary Crowdin SDK pods for the Screenshots feature. This setup is required to enable screenshot capture and upload. ```ruby use_frameworks! target 'your-app' do pod 'CrowdinSDK' pod 'CrowdinSDK/LoginFeature' // Required for Screenshots pod 'CrowdinSDK/Screenshots' // Required for Screenshots pod 'CrowdinSDK/Settings' // Optional. To add 'settings' button end ``` -------------------------------- ### iOS UI Test for Screenshot Automation Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation This Swift code sets up an XCTestCase to automate screenshot capture for localization testing. It requires Crowdin SDK configuration with distribution hash, source language, and access token. Ensure the SDK is started before running tests. ```swift final class AppleRemindersUITestsCrowdinScreenhsotTests: XCTestCase { private static let distributionHash = "{distribution_hash}" private static let sourceLanguage = "{source_language}" private static let accessToken = "{access_token}" override class func setUp() { // Requires to start SDK before running testScreenshots as it needs to get all supported localizations from Crowdin. startSDK(localization: sourceLanguage) } class func startSDK(localization: String) { let crowdinProviderConfig = CrowdinProviderConfig(hashString: Self.distributionHash, sourceLanguage: Self.sourceLanguage) let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(accessToken: Self.accessToken) .with(screenshotsEnabled: true) CrowdinSDK.currentLocalization = localization CrowdinSDK.startWithConfigSync(crowdinSDKConfig) } @MainActor func testScreenshots() throws { XCTAssert(CrowdinSDK.inSDKLocalizations.count > 0, "At least one target language should be set up in Crowdin.") let app = XCUIApplication() // Pass selected localization in test to the app. app.launchArguments = ["UI_TESTING", "CROWDIN_LANGUAGE_CODE=\(Self.sourceLanguage)"] app.launch() let addListBtn = app.otherElements.buttons.element(matching: .button, identifier: "addListBtn") _ = app.waitForExistence(timeout: 5) // Timeout for app to start SDK and show UI. // MAIN SCREEN var result = CrowdinSDK.captureOrUpdateScreenshotSync(name: "MAIN_SCREEN_\(Self.sourceLanguage)", image: XCUIScreen.main.screenshot().image, application: app) XCTAssertNil(result.error) } } ``` -------------------------------- ### Post-install Script for App Extensions Source: https://crowdin.github.io/mobile-sdk-ios/installation Add this post_install script to your Podfile to resolve building issues with app extensions when using the Crowdin SDK. ```ruby post_install do |installer| extension_api_exclude_pods = ['CrowdinSDK'] installer.pods_project.targets.each do |target| # the Pods contained into the `extension_api_exclude_pods` array # have to get the value (APPLICATION_EXTENSION_API_ONLY) set to NO # in order to work with service extensions if extension_api_exclude_pods.include? target.name target.build_configurations.each do |config| config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO' end end end end ``` -------------------------------- ### App Initialization with UI Testing Mode (AppDelegate) Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Conditionally set up your application environment based on the CROWDIN_UI_TESTING argument when using AppDelegate for app launch. ```swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if ProcessInfo.processInfo.arguments.contains("CROWDIN_UI_TESTING") { // Set up test data, mock services, etc. setupTestEnvironment() } else { // Normal app initialization setupNormalEnvironment() } return true } ``` -------------------------------- ### App Initialization with UI Testing Mode (SceneDelegate) Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Conditionally set up your application environment based on the CROWDIN_UI_TESTING argument when using SceneDelegate for app launch. ```swift func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } if ProcessInfo.processInfo.arguments.contains("CROWDIN_UI_TESTING") { // Set up test data, mock services, etc. setupTestEnvironment(windowScene: windowScene) } else { // Normal app initialization setupNormalEnvironment(windowScene: windowScene) } } ``` -------------------------------- ### Import Crowdin SDK in Swift Source: https://crowdin.github.io/mobile-sdk-ios/setup Import the Crowdin SDK at the beginning of your AppDelegate.swift file. ```swift import CrowdinSDK ``` -------------------------------- ### Add Crowdin SDK Pods to Podfile Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Include the necessary Crowdin SDK pods in your Podfile to enable Real-Time Preview and related features. Ensure 'CrowdinSDK/RealtimeUpdate' and 'CrowdinSDK/LoginFeature' are added. ```ruby use_frameworks! target 'your-app' do pod 'CrowdinSDK' pod 'CrowdinSDK/LoginFeature' // Required for Real-Time Preview pod 'CrowdinSDK/RealtimeUpdate' // Required for Real-Time Preview pod 'CrowdinSDK/Settings' // Optional. To add 'settings' floating button end ``` -------------------------------- ### Show Settings View in Swift Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To display the settings view in Swift, call the CrowdinSDK.showSettings() method. Ensure all features are set up with CrowdinSDKConfig. ```swift CrowdinSDK.showSettings() ``` -------------------------------- ### Add Crowdin SDK for Screenshots (Swift Package Manager) Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Configure your Package.swift file to include the Crowdin SDK's screenshot feature for your UI tests target. ```swift dependencies: [ .package(url: "https://github.com/crowdin/mobile-sdk-ios.git", .upToNextMajor(from: "VERSION")) ], targets: [ .target( name: "YourUITests", dependencies: [ .product(name: "CrowdinTestScreenshots", package: "CrowdinSDK") ] ) ] ``` -------------------------------- ### UI Tests Configuration with Access Token Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Configure UI tests with Crowdin details, an access token for authorization, and enable the screenshots feature. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{distribution_hash}", sourceLanguage: "{source_language}") let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(accessToken: "{access_token}") .with(screenshotsEnabled: true) CrowdinSDK.startWithConfigSync(crowdinSDKConfig) ``` -------------------------------- ### Import Crowdin SDK in Objective-C Source: https://crowdin.github.io/mobile-sdk-ios/setup Import the Crowdin SDK in your AppDelegate.m file. You can use either the @import or #import syntax. ```objectivec @import CrowdinSDK ``` ```objectivec #import ``` -------------------------------- ### Specify Target for CrowdinSDK in Podfile Source: https://crowdin.github.io/mobile-sdk-ios/installation Use this format in your Podfile to specify the target for the Crowdin SDK. ```ruby target 'MyApp' do pod 'CrowdinSDK' end ``` -------------------------------- ### Show Settings View in Objective-C Source: https://crowdin.github.io/mobile-sdk-ios/guides/sdk-structure To display the settings view in Objective-C, call the [CrowdinSDK showSettings] method. Ensure all features are set up with CrowdinSDKConfig. ```objective-c [CrowdinSDK showSettings] ``` -------------------------------- ### Enable Interval Updates in SDK Configuration Source: https://crowdin.github.io/mobile-sdk-ios/setup Configure the SDK to use interval updates by enabling the feature and specifying the update interval in seconds. The minimum interval is 900 seconds (15 minutes). ```swift .with(intervalUpdatesEnabled: true, interval: {interval}) ``` -------------------------------- ### Configure API Token Authorization in AppDelegate (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots Set up Crowdin SDK using an API access token for automated workflows in your Objective-C AppDelegate. ```objectivec CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@"" organizationName:@"{organization_name}"]; CrowdinSDKConfig *config = [[[[CrowdinSDKConfig config] withCrowdinProviderConfig:crowdinProviderConfig] withScreenshotsEnabled:YES] withAccessToken:@"your_access_token"]; ``` -------------------------------- ### Add Swift Library Search Path Source: https://crowdin.github.io/mobile-sdk-ios/setup For pure Objective-C projects, add this path to your Library Search Paths in Xcode to ensure Swift libraries are found. ```bash $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) ``` -------------------------------- ### Crowdin SDK Configuration in SceneDelegate.swift Source: https://crowdin.github.io/mobile-sdk-ios/example This snippet shows the configuration variables needed in `SceneDelegate.swift` for the Crowdin iOS SDK. It includes placeholders for distribution hash, source language, and authentication credentials (OAuth or access token). ```swift private let distributionHash = "your_distribution_hash" // Crowdin OTA Content Delivery distribution hash private let sourceLanguage = "source_language" // Crowdin project source language (e.g. "en") // Authentication - use either OAuth credentials or access token // OAuth authentication: private let clientId = "your_client_id" // Crowdin OAuth Client ID (needed for Screenshots and Real-Time Preview features) private let clientSecret = "your_client_secret" // Crowdin OAuth Client Secret (needed for Screenshots and Real-Time Preview features) // OR access token authentication (alternative to OAuth): private let accessToken = "your_access_token" // Crowdin access token (can be used instead of OAuth for Screenshots and Real-Time Preview features) ``` -------------------------------- ### Main App Configuration for Screenshots Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Configure the main app with Crowdin details and disable the settings button during UI tests to prevent it from appearing in screenshots. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{distribution_hash}", sourceLanguage: "{source_language}") let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(settingsEnabled: !isTesting) // Disable settings button during UI tests if it's enabled. CrowdinSDK.startWithConfig(crowdinSDKConfig) ``` -------------------------------- ### Configure OAuth Authorization in AppDelegate (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Set up OAuth-based authorization using Objective-C in your AppDelegate. This involves initializing CrowdinProviderConfig and CrowdinLoginConfig. ```objectivec CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"{your_distribution_hash}" sourceLanguage:@"{source_language}" organizationName:@"{organization_name}"]; NSError *error; CrowdinLoginConfig *loginConfig = [[CrowdinLoginConfig alloc] initWithClientId:@"{client_id}" clientSecret:@"{client_secret}" scope:@"project" error:&error]; if (!error) { CrowdinSDKConfig *config = [[[[CrowdinSDKConfig config] withCrowdinProviderConfig:crowdinProviderConfig] withRealtimeUpdatesEnabled:YES] withLoginConfig:loginConfig]; [CrowdinSDK startWithConfig:config completion:^{ // SDK is ready to use, put code to change language, etc. here }]; } else { NSLog(@"%@", error.localizedDescription); // CrowdinLoginConfig initialization error handling } ``` -------------------------------- ### Basic Screenshot Capture Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots Use this method for a straightforward capture of a new screenshot. It requires a unique name, typically generated dynamically. ```swift CrowdinSDK.captureScreenshot(name: String(Date().timeIntervalSince1970)) { print("Screenshot captured") } errorHandler: { error in print("Screenshot capture failed with error - " + (error?.localizedDescription ?? "")) } ``` -------------------------------- ### Configure OAuth Authorization in AppDelegate (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Set up OAuth-based authorization by configuring CrowdinProviderConfig and CrowdinLoginConfig in your AppDelegate. This method is suitable for development and testing. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}", sourceLanguage: "{source_language}", organizationName: "{organization_name}") // Optional. Required for Enterprise only var loginConfig: CrowdinLoginConfig do { loginConfig = try CrowdinLoginConfig(clientId: "{client_id}", clientSecret: "{client_secret}", scope: "project", redirectURI: "{redirectURI}") } catch { print(error) // CrowdinLoginConfig initialization error handling } let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(realtimeUpdatesEnabled: true) .with(loginConfig: loginConfig) .with(settingsEnabled: true) CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: { // SDK is ready to use, put code to change language, etc. here }) ``` -------------------------------- ### Set Up Custom Log Callback Source: https://crowdin.github.io/mobile-sdk-ios/guides/debug-and-logging Subscribe to receive log messages from the Crowdin SDK. This callback is invoked every time a new log is created, allowing you to process or display log information. ```swift CrowdinSDK.setOnLogCallback { logMessage in print("LOG MESSAGE - \(logMessage)") } ``` -------------------------------- ### Handle OAuth Callback in AppDelegate (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Implement the application:openURL:options: method in Objective-C to manage Crowdin SDK's OAuth authorization callbacks within your AppDelegate. ```objectivec - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { return [CrowdinSDK handleWithUrl:url]; } ``` -------------------------------- ### Enable UI Testing Mode in Tests Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Add the CROWDIN_UI_TESTING launch argument to your XCUIApplication instance to enable UI testing mode within your Xcode tests. ```swift let app = XCUIApplication() app.launchArguments = ["CROWDIN_UI_TESTING"] app.launch() ``` -------------------------------- ### Add CrowdinSDK to Podfile Source: https://crowdin.github.io/mobile-sdk-ios/installation Add this line to your Podfile to include the Crowdin iOS SDK via Cocoapods. ```ruby pod 'CrowdinSDK' ``` -------------------------------- ### Enable SDK Controls Widget in Configuration Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/sdk-controls Add this option to your Crowdin SDK configuration to enable the SDK Controls widget. ```swift .with(settingsEnabled: true) # To enable SDK Controls widget ``` -------------------------------- ### Handle OAuth Callback in AppDelegate (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Implement the application:openURL:options: method in your AppDelegate to handle authorization callbacks from Crowdin for OAuth. ```swift func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { CrowdinSDK.handle(url: url) } ``` -------------------------------- ### Add Localization Download Handler Source: https://crowdin.github.io/mobile-sdk-ios/setup Register a closure to be executed every time a new localization is downloaded. This is useful for triggering UI updates or processing new data. The handler can be removed later using its ID. ```swift let handlerId = CrowdinSDK.addDownloadHandler { print("New localization downloaded!") // Perform additional actions, such as updating the UI } // Optionally, you can remove the handler later if needed CrowdinSDK.removeDownloadHandler(handlerId) ``` -------------------------------- ### Configure API Token Authorization in AppDelegate (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Set up API Token-based authorization in your AppDelegate using Swift. This bypasses OAuth and is suitable for automated workflows. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}", sourceLanguage: "{source_language}", organizationName: "{organization_name}") // Optional. Required for Enterprise only let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(realtimeUpdatesEnabled: true) .with(accessToken: "your_access_token") .with(settingsEnabled: true) ``` -------------------------------- ### Handle OAuth Callback in SceneDelegate (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview For applications using SceneDelegate, implement the scene:openURLContexts: method to process Crowdin SDK's OAuth authorization callbacks. ```swift func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { guard let url = URLContexts.first?.url else { return } CrowdinSDK.handle(url: url) } ``` -------------------------------- ### Specify Branch for CrowdinSDK in Podfile Source: https://crowdin.github.io/mobile-sdk-ios/installation You can specify an exact branch of the Crowdin iOS SDK in your Podfile using this syntax. ```ruby pod 'CrowdinSDK', :git => 'https://github.com/crowdin/mobile-sdk-ios.git', :branch => 'dev' ``` -------------------------------- ### App Configuration for Crowdin SDK Test Mode Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Configure your app's SceneDelegate to enable UI testing mode and set a specific locale for the Crowdin SDK. This allows for testing localized content and screenshots during development. ```swift // In SceneDelegate let arguments = ProcessInfo.processInfo.arguments let isTesting = arguments.contains("UI_TESTING") if isTesting, let locale = arguments.first(where: { $0.contains("CROWDIN_LANGUAGE_CODE") })?.split(separator: "=").last.map({ String($0) }) { // Configure SDK for testing with specific locale let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(accessToken: Self.accessToken) .with(screenshotsEnabled: true) CrowdinSDK.currentLocalization = locale CrowdinSDK.startWithConfig(crowdinSDKConfig) { // Initialize UI after SDK is configured } } ``` -------------------------------- ### SwiftUI Localization with Convenience Extension Source: https://crowdin.github.io/mobile-sdk-ios/setup Alternatively, use the `cw_localized` convenience extension for accessing localized strings in SwiftUI views. ```swift Text("key".cw_localized) ``` -------------------------------- ### Configure API Token Authorization in AppDelegate (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots Configure Crowdin SDK with an API access token for direct integration, bypassing OAuth, in your Swift AppDelegate. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}", sourceLanguage: "{source_language}", organizationName: "{organization_name}") // Optional. Required for Enterprise only let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(screenshotsEnabled: true) .with(accessToken: "your_access_token") .with(settingsEnabled: true) CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: { // SDK is ready to use, put code to change language, etc. here }) ``` -------------------------------- ### Handle OAuth Callback in SceneDelegate (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Implement the scene:openURLContexts: method in Objective-C within your SceneDelegate to handle Crowdin SDK's OAuth authorization callbacks. ```objectivec - (void)scene:(UIScene *)scene openURLContexts:(NSSet *)URLContexts { return [CrowdinSDK handleWithUrl:url]; } ``` -------------------------------- ### Configure OAuth-based Authorization in AppDelegate (Swift) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots Use this Swift code in your AppDelegate to set up OAuth-based authorization for Crowdin SDK, enabling screenshots and user login. ```swift let crowdinProviderConfig = CrowdinProviderConfig(hashString: "{your_distribution_hash}", sourceLanguage: "{source_language}", organizationName: "{organization_name}") // Optional. Required for Enterprise only var loginConfig: CrowdinLoginConfig do { loginConfig = try CrowdinLoginConfig(clientId: "{client_id}", clientSecret: "{client_secret}", scope: "project.screenshot", redirectURI: "{redirectURI}") } catch { print(error) // CrowdinLoginConfig initialization error handling } let crowdinSDKConfig = CrowdinSDKConfig.config() .with(crowdinProviderConfig: crowdinProviderConfig) .with(screenshotsEnabled: true) .with(loginConfig: loginConfig) .with(settingsEnabled: true) CrowdinSDK.startWithConfig(crowdinSDKConfig, completion: { // SDK is ready to use, put code to change language, etc. here }) ``` -------------------------------- ### Capture Screenshot Synchronously Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Use the captureOrUpdateScreenshotSync method to capture and upload a screenshot synchronously. Ensure the XCUIApplication instance is provided for context. ```swift CrowdinSDK.captureOrUpdateScreenshotSync( name: String, image: UIImage, application: XCUIApplication ) -> (result: ScreenshotUploadResult?, error: Error?) ``` -------------------------------- ### Configure API Token Authorization in AppDelegate (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/real-time-preview Configure API Token-based authorization in Objective-C within your AppDelegate. This method is ideal for CI/CD pipelines and automated processes. ```objectivec CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"{your_distribution_hash}" sourceLanguage:@"{source_language}" organizationName:@"{organization_name}"]; CrowdinSDKConfig *config = [[[[CrowdinSDKConfig config] withCrowdinProviderConfig:crowdinProviderConfig] withRealtimeUpdatesEnabled:YES] withAccessToken:@"your_access_token"]; ``` -------------------------------- ### Configure OAuth-based Authorization in AppDelegate (Objective-C) Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots This Objective-C code configures the Crowdin SDK for OAuth-based authorization, including screenshot functionality and user login, within your AppDelegate. ```objectivec CrowdinProviderConfig *crowdinProviderConfig = [[CrowdinProviderConfig alloc] initWithHashString:@"" sourceLanguage:@"" organizationName:@"{organization_name}"]; NSError *error; CrowdinLoginConfig *loginConfig = [[CrowdinLoginConfig alloc] initWithClientId:@"{client_id}" clientSecret:@"{client_secret}" scope:@"project.screenshot" error:&error]; if (!error) { CrowdinSDKConfig *config = [[[[CrowdinSDKConfig config] withCrowdinProviderConfig:crowdinProviderConfig] withScreenshotsEnabled:YES] withLoginConfig:loginConfig]; [CrowdinSDK startWithConfig:config completion:^{ // SDK is ready to use, put code to change language, etc. here }]; } else { NSLog(@"%@", error.localizedDescription); // CrowdinLoginConfig initialization error handling } ``` -------------------------------- ### Add Crowdin SDK for Screenshots (CocoaPods) Source: https://crowdin.github.io/mobile-sdk-ios/guides/screenshots-automation Add the Crowdin SDK's screenshot feature to your UI Tests target using CocoaPods. ```ruby target 'YourAppUITests' do pod 'CrowdinSDK/CrowdinTestScreenshots' end ``` -------------------------------- ### Enable Console Debugging Source: https://crowdin.github.io/mobile-sdk-ios/guides/debug-and-logging Add this option to your CrowdinSDKConfig to enable logging messages to the Xcode console. ```swift .with(debugEnabled: true) ``` -------------------------------- ### Add CrowdinSDK to Package.swift Source: https://crowdin.github.io/mobile-sdk-ios/installation Add the Crowdin iOS SDK to your project directly in Package.swift using this dependency declaration. ```swift dependencies: [ .package(url: "https://github.com/crowdin/mobile-sdk-ios.git", from: "1.10.1") ] ``` -------------------------------- ### Specify Version Range for CrowdinSDK in Package.swift Source: https://crowdin.github.io/mobile-sdk-ios/installation For better version control, you can specify an exact version or version range for the Crowdin iOS SDK in your Package.swift. ```swift .package(url: "https://github.com/crowdin/mobile-sdk-ios.git", .upToNextMajor(from: "1.10.1")) ``` -------------------------------- ### SwiftUI Localization with NSLocalizedString Source: https://crowdin.github.io/mobile-sdk-ios/setup For SwiftUI projects, use the standard `NSLocalizedString` macro to access localized strings. ```swift Text(NSLocalizedString("key", comment: "comment")) ``` -------------------------------- ### Set Current Localization Programmatically Source: https://crowdin.github.io/mobile-sdk-ios/setup Change the SDK's target language on the fly by setting the `currentLocalization` property. This triggers a localization download if necessary. Setting it to `nil` reverts to device locale detection. ```swift import CrowdinSDK // Set the current localization to German CrowdinSDK.currentLocalization = "" // ... // Get the current localization if let currentLocale = CrowdinSDK.currentLocalization { print("Current localization: \(currentLocale)") } else { print("Using default localization") } ``` -------------------------------- ### Set Current Localization with Completion Handler Source: https://crowdin.github.io/mobile-sdk-ios/setup Use this method to change the SDK's target language and receive a callback upon completion or error. Manually update the UI after the localization refresh. ```swift CrowdinSDK.setCurrentLocalization("") { error in if let error = error { print("Localization switch failed: \(error.localizedDescription)") return } // Reload your UI here. } ``` -------------------------------- ### Capture and Update Existing Screenshot Source: https://crowdin.github.io/mobile-sdk-ios/advanced-features/screenshots This method is ideal for updating an existing screenshot in your Crowdin project, helping to maintain organization by replacing rather than creating new ones. It requires the name of the screenshot to be updated. ```swift CrowdinSDK.captureAndUpdateScreenshot(name: "{screenshot_name}") { result in switch result { case .new: print("New screenshot captured") case .udpated: print("Screenshot updated") } } errorHandler: { error in print("Error: \(error)") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.