Fast Integration with IPC SDK for iOS

Last Updated on : 2022-03-03 07:30:36download

The IPC SDK for iOS helps you implement IP camera (IPC) functionalities on top of the modules provided by the Smart Security App SDK, such as user management, device pairing, home management, and device management.

The SDK supports iOS 9.0 and later. IPCs do not support cloud development solutions. You must integrate the IPC SDK with the Smart Security App SDK during the app development.

Modules

Module Description
TuyaSmartActivatorKit Device pairing SDK
TuyaSmartCameraKit Extension SDK for Tuya-powered IPCs

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

Environment settings

Fast Integration

Add the following code block to the Podfile:

platform :ios, '9.0'

target 'your_target_name' do

  pod "TuyaSmartActivatorKit"
	pod "TuyaSmartCameraKit"
	# pod "TuyaSmartCameraT"

end

To support peer-to-peer (P2P) 1.0 devices, you must add pod "TuyaSmartCameraT", and run the command pod update in the project root directory.

For more information about CocoaPods, see CocoaPods Guides.

Add permissions

// need to add below authorization in info.plist
Privacy - Microphone Usage Description
Privacy - Photo Library Additions Usage Description

Initialize the SDK

  1. Open the project settings, choose Target > General, and then set Bundle Identifier to the bundle ID for iOS that is specified on the Tuya IoT Platform.

  2. Import the security image downloaded in Preparation to the root directory of the project, rename it as t_s.bmp. Go to Project Settings > Target > Build Phases, and add this image to Copy Bundle Resources.

  3. 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 <TuyaSmartBaseKit/TuyaSmartBaseKit.h>
    #import <TuyaSmartActivatorKit/TuyaSmartActivatorKit.h>
    #import <TuyaSmartCameraKit/TuyaSmartCameraKit.h>
    
  4. 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 IoT Platform are used for the initialization.

    Objective-C:

    [[TuyaSmartSDK sharedInstance] startWithAppKey:<#your_app_key#> secretKey:<#your_secret_key#>];
    

    Swift:

    TuyaSmartSDK.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
    [[TuyaSmartSDK sharedInstance] setDebugMode:YES];
#else
#endif

Swift:

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

We recommend that you could use the real device for debugging during the development. Using the simulator will cause some functions to be unavailable.

Run the demo app

You can view the demo app in the IPC SDK sample repository. Follow the instructions in the Smart Life App SDK demo app, and configure the values of BundleId, AppKey, AppSecret, and security image.

Based on the features of the Smart Life App SDK demo app, the IPC SDK demo app is added with the control panel module for IPCs to implement the following pages:

  • Live streaming: P2P connections of IPCs, live video playing, video recording, screenshots, video talk, and more.
  • Playback: retrieval and playback of video footage in an IPC storage 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.