SDK Integration

Last Updated on : 2024-04-10 02:38:08download

This topic describes how to integrate MiniApp SDK into your iOS project. This helps you build a Smart Life miniapp and run it on your IoT app.

Preparation

Finish the following operations on the Tuya IoT Development Platform before you integrate MiniApp SDK into your project:

  • Register a developer account, create a product, define data points (DPs), and continue with subsequent steps.
  • Create an app based on Smart Life App SDK and get the key information that is required to activate the SDK. For more information, see Preparation.

Prerequisites

The Smart Life App SDK is integrated into your project. For more information, see Fast Integration with Smart Life App SDK.

Integrate with MiniApp SDK

MiniApp SDK supports pod integration.

  1. Install CocoaPods.

    The components of the MiniApp SDK are managed with CocoaPods. Run the following command to install CocoaPods on your computer.

    sudo gem install cocoapods
    pod setup
    
  2. Create a Podfile.

    Navigate to the project root directory and verify the presence of a Podfile. If it is not found, create one.

    touch Podile
    

    Add the following code block to the Podfile.

    source 'https://github.com/tuya/tuya-pod-specs.git'
    platform :ios, '11.0'
    inhibit_all_warnings!
    
    target 'Your_Project_Name' do
        pod "ThingSmartMiniAppBizBundle"
    end
    
  3. Update the CocoaPods dependencies.

    // Update the repo source and component versions.
    pod update
    // Update the component version.
    pod update --no-repo-update
    

Add permission description

To protect user privacy, Apple requires apps to ask the user for permission to access system services, such as camera, photos, Bluetooth, microphone, and location.

Permission name Property list key Respective API
Read access to the user’s photo library NSPhotoLibraryUsageDescription
  • chooseImage
  • chooseMedia
Write access to the user’s photo library NSPhotoLibraryAddUsageDescription saveToAlbum
Camera NSCameraUsageDescription
  • scanCode
  • chooseImage
  • chooseMedia
Bluetooth NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription Pairing and device control APIs
Microphone NSMicrophoneUsageDescription chooseMedia

Set supported orientations

SDK Integration

The miniapp pages can work in both portrait and landscape. To enable changing screen orientation, select the supported orientations in your project.

Open a miniapp

Import the header file

#import <ThingSmartMiniAppBizBundle/ThingSmartMiniAppBizBundle.h>

Open a miniapp

// Open a miniapp by appId.
[[ThingMiniAppClient coreClient] openMiniAppByAppId:@"tydhopggfziofo1h9h"];

// Open a miniapp by URL.
[[ThingMiniAppClient coreClient] openMiniAppByUrl:@"godzilla://tydhopggfziofo1h9h/" params:@{}];

// Open a miniapp by QR code scanning.
[[ThingMiniAppClient coreClient] openMiniAppByQrcode:@"qrcodeString" params:@{}];

For more information about how to make other API requests, see Quick Start.

Import capability package

To expand the possibilities of your miniapp, Tuya encapsulates commonly used capabilities into different capability packages. You can integrate the desired capability package into your project to access the included API resources and thus easily implement the respective business functionality.

Basic capability package

This package provides most API resources similar to those supported by WeChat Mini Program, for example, upload, download, recording, interaction, and file operations. We recommend that you integrate the basic capability package by default.

pod 'ThingSmartBaseKitBizBundle'

Business capability package

This package provides typical APIs enabled by Tuya. For example, query multilingual settings and open control panels. We recommend that you integrate the business capability package by default.

pod 'ThingSmartBizKitBizBundle'

Home management capability package

This package provides the capability to query information about homes. These capabilities are essential to Tuya-enabled business. A home is the largest unit to manage smart scenes. To integrate the home management capability package, in addition to the preceding capability dependency, integrate the Home Management UI BizBundle into your project.

Device control capability package

This package encapsulates device control capabilities that help implement device control, device removal, and device status listening. For more information, see Device Control UI BizBundle.

pod 'ThingSmartDeviceKitBizBundle'

To enable device control over Bluetooth, integrate the following components.

pod 'ThingBLEInterfaceImpl'
pod 'ThingBLEMeshInterfaceImpl'

Map capability package

This package encapsulates map capabilities that help implement typical features, such as location and geofencing.

pod 'ThingSmartMapKitBizBundle'

Media capability package

To use the media components video and camera, integrate the media capability package into your project.

pod 'ThingSmartMediaKitBizBundle'

P2P transmission capability package

This package encapsulates P2P connection establishment, transmission, and other capabilities, including P2P initialization, connection, upload, download, and destruction features. It applies to robot vacuums, door locks, IPCs, and many more.

pod 'ThingSmartP2PKitBizBundle'

IPC capability package

This package encapsulates IPC business capabilities, including an IPC YUV player, doorbell call, cloud storage signature, and other features. It applies to IPCs, door locks, robot vacuums, and many more.

pod 'ThingSmartIPCKitBizBundle'