# iOS SDK

# Introduction

DUIX ONE-Offline iOS SDK is a local version of the DUIX ONE SDK that provides offline capabilities. It allows developers to integrate DUIX's AI capabilities into iOS applications without requiring an internet connection.

# Integration Guide

# Environment Requirements

  • Xcode 12.0 or above
  • iOS 11.0 or above
  • Swift 5.0 or above (for Swift projects)

# Integration Steps

# 1. Using CocoaPods

Add the following to your Podfile:

platform :ios, '11.0'

target 'YourApp' do
  use_frameworks!
  
  # DUIX ONE-Offline SDK
  pod 'DuixOfflineSDK', '~> x.x.x'
end

Replace x.x.x with the latest version of the SDK.

Then run:

pod install

# 2. Using Swift Package Manager

Add the package dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/duix/duix-offline-ios.git", .upToNextMajor(from: "x.x.x"))
]

Or add it directly in Xcode: File > Swift Packages > Add Package Dependency

# 3. Initialize SDK

Initialize the SDK in your AppDelegate:

# Swift
import DuixOfflineSDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Initialize DUIX ONE-Offline SDK
        let config = DuixOfflineConfig(appId: "your_app_id", appKey: "your_app_key")
        DuixOfflineSDK.initialize(with: config)
        
        return true
    }
}
# Objective-C
#import <DuixOfflineSDK/DuixOfflineSDK.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Initialize DUIX ONE-Offline SDK
    DuixOfflineConfig *config = [[DuixOfflineConfig alloc] initWithAppId:@"your_app_id" appKey:@"your_app_key"];
    [DuixOfflineSDK initializeWithConfig:config];
    
    return YES;
}

@end

# API Reference

# Core Classes

# DuixOfflineSDK

The main entry point for the SDK.

# Swift
// Initialize SDK
DuixOfflineSDK.initialize(with: config)

// Check if SDK is initialized
let isInitialized = DuixOfflineSDK.isInitialized()

// Get SDK version
let version = DuixOfflineSDK.version()
# Objective-C
// Initialize SDK
[DuixOfflineSDK initializeWithConfig:config];

// Check if SDK is initialized
BOOL isInitialized = [DuixOfflineSDK isInitialized];

// Get SDK version
NSString *version = [DuixOfflineSDK version];

# DuixOfflineConfig

Configuration class for the SDK.

# Swift
let config = DuixOfflineConfig(
    appId: "your_app_id",
    appKey: "your_app_key",
    debugMode: true,
    logLevel: .verbose
)
# Objective-C
DuixOfflineConfig *config = [[DuixOfflineConfig alloc] initWithAppId:@"your_app_id"
                                                              appKey:@"your_app_key"];
config.debugMode = YES;
config.logLevel = DuixLogLevelVerbose;

# Feature APIs

# Text Recognition

# Swift
// Create text recognizer
let recognizer = DuixOfflineSDK.createTextRecognizer()

// Recognize text from image
recognizer.recognizeText(from: image) { result, error in
    if let error = error {
        // Handle error
        let code = error.code
        let message = error.message
    } else if let result = result {
        // Handle success
        let text = result.text
    }
}

// Release resources when done
recognizer.release()
# Objective-C
// Create text recognizer
DuixTextRecognizer *recognizer = [DuixOfflineSDK createTextRecognizer];

// Recognize text from image
[recognizer recognizeTextFrom:image completion:^(DuixTextRecognitionResult *result, DuixError *error) {
    if (error) {
        // Handle error
        NSInteger code = error.code;
        NSString *message = error.message;
    } else {
        // Handle success
        NSString *text = result.text;
    }
}];

// Release resources when done
[recognizer release];

# Image Classification

# Swift
// Create image classifier
let classifier = DuixOfflineSDK.createImageClassifier()

// Classify image
classifier.classify(image) { result, error in
    if let error = error {
        // Handle error
    } else if let result = result {
        // Handle success
        let classifications = result.classifications
    }
}

// Release resources when done
classifier.release()
# Objective-C
// Create image classifier
DuixImageClassifier *classifier = [DuixOfflineSDK createImageClassifier];

// Classify image
[classifier classifyImage:image completion:^(DuixClassificationResult *result, DuixError *error) {
    if (error) {
        // Handle error
    } else {
        // Handle success
        NSArray<DuixClassification *> *classifications = result.classifications;
    }
}];

// Release resources when done
[classifier release];

# Error Codes

Code Description
1001 SDK not initialized
1002 Invalid parameters
1003 License expired
2001 Model loading failed
2002 Processing error
3001 Out of memory
3002 Internal error

# Best Practices

  1. Resource Management: Always release resources when you're done using them to prevent memory leaks.

  2. Error Handling: Implement proper error handling to provide a good user experience.

  3. Performance Optimization:

    • Process images at an appropriate resolution
    • Run heavy operations in background threads
    • Cache results when appropriate
  4. Battery Efficiency: Minimize continuous processing to conserve battery life.

  5. Memory Management: Be mindful of memory usage, especially when processing large images or videos.

# FAQ

Q: How large are the offline models?

A: The size of offline models varies depending on the features you use, typically ranging from 10MB to 100MB.

Q: Can I use the SDK without an internet connection?

A: Yes, once the SDK is properly initialized and the models are downloaded, it can function completely offline.

Q: Does the SDK support iPad?

A: Yes, the SDK fully supports iPad devices running iOS 11.0 or later.

Q: How often are the offline models updated?

A: We release model updates quarterly, but you can continue using existing models indefinitely.

Q: Is there a limit to the number of API calls in offline mode?

A: No, there are no API call limits in offline mode, but there may be device performance limitations.

# Support

For technical support, please contact us at support@duix.com or visit our developer portal at https://developer.duix.com.