Integration with IPC SDK for iOS

Last Updated on : 2024-06-14 10:08:40download

IPC SDK helps you implement IP camera (IPC) functionalities on top of the modules provided by Smart Life App SDK, such as user management, device pairing, home management, and device management. Therefore, the Smart Life App SDK must be integrated before you integrate or update the IPC SDK for your project. For more information, see Fast Integration with Smart Life App SDK for iOS.

The earliest iOS version supported by the SDK is iOS 11.0. IPCs do not support cloud development solutions. You must integrate the IPC SDK with the Smart Life App SDK during the app development.

Modules

Module Description
ThingSmartCameraKit Extension SDK for Tuya-enabled IPCs

ThingSmartCameraKit is not a separate library. It depends on certain basic libraries. For more information, see SDK Architecture.

Set up the environment

Integrate with the SDK

Smart Life App SDK v5.0.0 has the security mechanism enhanced. You must download the SDK dedicated to your app security to improve your app development.

Add the following code block to the Podfile:

source 'https://github.com/tuya/tuya-pod-specs.git'
platform :ios, '11.0'

target 'your_target_name' do
  # Build and get ThingSmartCryption from the Tuya Developer Platform (https://platform.tuya.com).
  # After the official edition is purchased, rebuild the SDK on the Tuya Developer Platform and integrate it into your project.
  # The dot slash (./) notation represents that the files that are obtained after `ios_core_sdk.tar.gz` is extracted are put to the directory at the same directory as `podfile`.
  # To use another directory, change the `path` to your desired directory.
  pod "ThingSmartCryption", :path =>'./'
  pod "ThingSmartCameraKit"
end

The IPC SDK does not support P2P 1.0 devices by default. In this case, the value of p2pType for this type of device is 1. To use this type of device, contact Tuya’s account manager.

Add permissions

The IPC SDK requires permissions to access the album and use the microphone. Make sure you have added the following permission declaration to info.plist of your project. Otherwise, the app might crash during video recording, screenshot capturing, or video talks.

// Add the following permission declaration to `info.plist` of your project.
Privacy - Microphone Usage Description
Privacy - Photo Library Additions Usage Description

Initialize the SDK

  1. Open the project settings, click Target > General, and then modify Bundle Identifier to the iOS Bundle ID of the app that is registered on the Tuya Developer Platform.

  2. Add the following content to the PrefixHeader.pch file of the project. For a Swift project, the following content can be added to the bridging header file xxx_Bridging-Header.h.

    #import <ThingSmartBaseKit/ThingSmartBaseKit.h>
    #import <ThingSmartCameraKit/ThingSmartCameraKit.h>
    
  3. Open the AppDelegate.m file and initialize the SDK by calling the method [AppDelegate application:didFinishLaunchingWithOptions:]. The values of AppKey and AppSecret generated on the Tuya Developer Platform are used for the initialization.

    • Objective-C:

      [[ThingSmartSDK sharedInstance] startWithAppKey:<#your_app_key#><#your_app_key#> secretKey:<#your_secret_key#>];
      
    • Swift:

      ThingSmartSDK.sharedInstance()?.start(withAppKey: <#your_app_key#>, secretKey: <#your_secret_key#>)
      

Now, the SDK is activated and you are ready for app development.

Modify the main function

After the video is streamed, the app goes to the background, stays for a while, and then comes back to the foreground. This might cause the app to crash. Error message: Terminated due to signal 13. To prevent this crash, add the following code block to the project:

  • Objective-C: main.m

    int main(int argc, char * argv[]) {
        @autoreleasepool {
    
            struct sigaction sa;
            sa.sa_handler = SIG_IGN;
            sigemptyset(&sa.sa_mask);
            sa.sa_flags = 0;
    
            if (sigaction(SIGPIPE, &sa, NULL) < 0) {
                perror("cannot ignore SIGPIPE");
                return -1;
            }
    
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    }
    
  • Swift: AppDelegate.swift

    let handler: @convention(c) (Int32) -> () = { sig in
            // handle the signal somehow
            print("error", sig)
        }
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            // Override point for customization after application launch.
    
            signal(SIGPIPE, handler)
            return true
        }
    

Enable the debug mode

During the development, you can enable the debug mode and print logs for troubleshooting.

  • Objective-C:

    #ifdef DEBUG
        [[ThingSmartSDK sharedInstance] setDebugMode:YES];
        [[ThingSmartCameraSDK sharedInstance] setDebugMode:YES];
    #else
    #endif
    
  • Swift:

    #if DEBUG
    ThingSmartSDK.sharedInstance()?.debugMode = true
    ThingSmartCameraSDK.sharedInstance()?.debugMode = true
    #else
    #endif
    

    During the development, we recommend that you use a real device for debugging. If a simulator is used for debugging, certain features might be unavailable.

Run the demo app

Smart Life App SDK demo app supports the IPC features. Follow the instructions in the Smart Life App SDK demo app, and configure the values of BundleId, AppKey, and AppSecret.

The demo app that is created in the sample project of IPC SDK is used for reference only. Do not use the demo app for commercial purposes. For more information, see Tuya Developing Service Agreement.

The demo app supports the following IPC features:

  • Live streaming: P2P connections of IPCs, live video playing, video recording, screenshot capturing, video talks, and more.
  • Playback: retrieval and playback of video footage from an SD card, and use of timeline components.
  • Cloud Storage for Videos: service subscription, status query, and retrieval and playback of cloud-stored videos and cloud storage events.
  • Messages: retrieval and display of alerts.
  • Settings: use of standard data points for IPCs.