IPCs

Last Updated on : 2023-05-22 06:38:30

A list of devices can be obtained based on homes. An IP camera (IPC) can be determined by device type. Then, an IPC object can be created with the information provided by TuyaSmartDeviceModel.

Determine an IPC

The TuyaSmartDeviceModel+IPCSDK class can be used to check whether a device is an IPC.

API description

Checks whether a device is an IPC.

- (BOOL)isIPCDevice;

Example

ObjC

[[TuyaSmartHomeManager new] getHomeListWithSuccess:^(NSArray<TuyaSmartHomeModel *> *homes) {
        [homes enumerateObjectsUsingBlock:^(TuyaSmartHomeModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:obj.homeId];
                [home getHomeDetailWithSuccess:^(TuyaSmartHomeModel *homeModel) {
                        [home.deviceList enumerateObjectsUsingBlock:^(TuyaSmartDeviceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj isIPCDevice]) {
                        NSLog(@"%@ is an IPC", obj.name);
                    }
        }];
        } failure:^(NSError *error) {

        }];
    }];
} failure:^(NSError *error) {

}];

Swift

let homeManager = TuyaSmartHomeManager()
homeManager.getHomeList(success: { homeList in
    homeList?.forEach({ homeModel in
        let home = TuyaSmartHome(homeId: homeModel.homeId)
        home?.getDetailWithSuccess({ _ in
            home?.deviceList.forEach({ deviceModel in
                if deviceModel.isIPCDevice() {
                    print(deviceModel.name!, "is an IPC")
                }
            })
        }, failure: { error in

        })
    })
}) { error in

}

This example only shows the simplest process to get an IPC. In the actual development, you must display and manage devices based on the specific logic of UI interaction.

Create an IPC instance

Classes (Protocols)

Class name (protocol name) Description
TuyaSmartCameraFactory The utility class to create IPC configurations and objects.
TuyaSmartCameraConfig The IPC configuration class. You can leave it as is.
TuyaSmartCameraType The IPC API protocol. The implementation varies depending on different IPC firmware types.
TuyaSmartCameraDelegate The IPC delegate that provides the callback that returns the result of an IPC method.

TuyaSmartCameraFactory provides the factory method to create an IPC control object.

API description

Creates an IPC instance object.

+ (id<TuyaSmartCameraType>)cameraWithP2PType:(id)type deviceId:(NSString *)devId delegate:(id<TuyaSmartCameraDelegate>)delegate;

Parameters

Parameter Description
type The peer-to-peer (P2P) type. It is set to a value of Number type.
devId The device ID.
delegate The delegate object.

Return value

Type Description
id The implementation object of the IPC API.

Get the P2P type

Tuya-powered IPCs support three P2P channel implementation solutions. The IPC SDK initializes different IPC implementation objects based on the P2P type. You can use TuyaSmartDeviceModel+IPCSDK to get the specific P2P type.

API description

Returns the P2P type.

- (NSInteger)p2pType;

Example

ObjC

// `deviceModel` is the data model of the listed IPCs.
id<TuyaSmartCameraType> camera = [TuyaSmartCameraFactory cameraWithP2PType:@(deviceModel.p2pType) deviceId:deviceModel.devId delegate:self];

Swift

let camera = TuyaSmartCameraFactory.camera(withP2PType: deviceModel.p2pType(), deviceId: deviceModel.devId, delegate: self)

In this example, delegate is set to self and TuyaSmartCameraDelegate must be implemented.