Skip to content

iOS Preparation

Development Environment Requirements

  • Xcode: Latest version recommended
  • iOS: iOS 10.0 or higher
  • Swift: Swift 5.0 or higher
  • CocoaPods: 1.10.0 or higher

Project Configuration

1. Add Dependencies

Add UJU Ad SDK dependencies to your Podfile:

ruby
platform :ios, '10.0'

pod 'UjuAdSDK', '~> 1.0.0'

Then run pod install to install the dependencies.

2. Configure Info.plist

Add necessary configurations to Info.plist file:

xml
<!-- Network permissions -->
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

<!-- Privacy permissions -->
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to provide you with personalized ads.</string>

<!-- Facebook Audience Network configuration (if using) -->
<key>FacebookAppID</key>
<string>YOUR_FACEBOOK_APP_ID</string>
<key>FacebookDisplayName</key>
<string>YOUR_APP_NAME</string>

<!-- AdMob configuration (if using) -->
<key>GADApplicationIdentifier</key>
<string>YOUR_ADMOB_APP_ID</string>

3. Enable Required Capabilities

In Xcode, enable the following capabilities:

  • Background Modes: Enable "Background fetch" and "Remote notifications"
  • Push Notifications: Enable if you plan to use push notifications

SDK Initialization

Initialize the SDK in your AppDelegate.swift file:

swift
import UIKit
import UjuAdSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        // Initialize UJU SDK
        initializeUjuSDK()
        
        return true
    }
    
    private func initializeUjuSDK() {
        let config = UjuAdInitConfig(
            appId: "YOUR_APP_ID",
            appKey: "YOUR_APP_KEY",
            isDebug: true
        )
        
        UjuAdSDK.initSDK(with: config)
        UjuAdSDK.start { success, error in
            if success {
                print("UJU SDK initialized successfully")
            } else {
                print("UJU SDK initialization failed: \(error?.localizedDescription ?? \"Unknown error\")")
            }
        }
    }
}

Testing

Test Mode

Enable test mode during development:

swift
// Enable test mode
UjuAdSDK.setTestMode(true)

Test Devices

Add test devices to avoid invalid clicks:

swift
// Add test device
UjuAdSDK.addTestDevice("YOUR_DEVICE_ID")

Best Practices

  • Early initialization: Initialize the SDK as early as possible in the application launch process
  • Permission handling: Request user tracking permission before loading ads
  • Error handling: Implement proper error handling for ad loading failures
  • Ad preloading: Preload ads before they need to be displayed
  • Frequency control: Control ad display frequency to avoid user annoyance

Common Questions

Q: Why isn't the SDK initializing?

A: Possible reasons:

  • Incorrect App ID or App Key
  • Network connection issues
  • iOS version incompatibility
  • Missing required permissions

Q: How to get the device ID for testing?

A: You can find the device ID in the Xcode console logs when running the app with test mode enabled.

Q: What permissions are required for iOS ads?

A: Required permissions:

  • Network access (automatic)
  • User tracking permission (required for iOS 14+)

Optional permissions:

  • Location (for better ad targeting)
  • Camera/microphone (for certain ad formats)

Next Steps

After completing the preparation work, you can proceed with: