Device Sharing

Last Updated on : 2023-07-13 06:43:11download

A user can share a device in a home with other users so that the other users can control the device. The users who receive a sharing invitation can control the device by using their app account.

Each device can be simultaneously shared with up to 20 users.

Integrate with the class

Class name Description
ThingSmartHomeDeviceShare Provides the capabilities to share devices.

Objective-C:

#import <ThingSmartDeviceKit/ThingSmartHomeDeviceShare.h>

Swift:

import ThingSmartDeviceKit

Share devices

Share one or more devices

Shares one or more devices with a specific user. Each device can be simultaneously shared with up to 20 users.

The API methods addShareWithHomeId:countryCode:userAccount:devIds:failure: and addDeviceShareWithHomeId:countryCode:userAccount:devId:success:failure: will soon be deprecated. We recommend that you timely update the API.

API description

- (void)addDeviceShareWithRequestModel:(ThingSmartDeviceShareRequestModel *)requestModel
                            success:(void(^)(ThingSmartShareMemberModel *model))success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
requestModel The request object.
success The success callback.
failure The failure callback.

Description of ThingSmartDeviceShareRequestModel

@interface ThingSmartDeviceShareRequestModel : NSObject

/// The ID of the home to which the shared devices belong.
@property (nonatomic, assign) long long homeID;

/// The country code of the user who receives a sharing invitation.
@property (nonatomic, copy) NSString *countryCode;

/// The account of the user who receives a sharing invitation.
@property (nonatomic, copy) NSString *userAccount;

/// The list of device IDs for sharing.
@property (nonatomic, copy) NSArray<NSString *> *devIds;

@end

Example

Objective-C:

- (void)addMemberShare {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

ThingSmartDeviceShareRequestModel *model = [ThingSmartDeviceShareRequestModel new];
model.homeID = Home ID;
model.countryCode = Country code;
model.userAccount = Target user account;
model.devIds = List of shared device IDs;

[self.deviceShare addDeviceShareWithRequestModel:model success:^(ThingSmartShareMemberModel * _Nonnull model) {
    //do something
} failure:^(NSError *error) {
    //do something
}];
}

Swift:

func addMemberShare() {
var model = ThingSmartDeviceShareRequestModel.init()
model.homeID = Home ID
model.countryCode =
model.userAccount = Target user account
model.devIds = List of shared device IDs

deviceShare.add(with: model) { (_) in
    //do something
} failure: { (_) in
    //do something
}
}

Shared devices

Shares multiple devices to a specific user and adds these devices following earlier sharing with the user. Each device can be simultaneously shared with up to 20 users.

API description

- (void)addShareWithMemberId:(NSInteger)memberId
                    devIds:(NSArray <NSString *> *)devIds
                    success:(ThingSuccessHandler)success
                    failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The ID of the user who receives a sharing invitation.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)addMemberShare {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare addShareWithMemberId:memberId devIds:(NSArray<NSString *> *) success:^{
    NSLog(@"addShare success");
} failure:^(NSError *error) {
    NSLog(@"addShare failure: %@", error);
}];
}

Swift:

func addMemberShare() {
deviceShare?.add(withMemberId: memberId, devIds: ["devIds"], success: {
    print("addShare success")
}, failure: { (error) in
    if let e = error {
        print("addShare failure: \(e)")
    }
})
}

(Legacy) Share multiple devices and overwrite earlier sharing

Shares multiple devices to a specific user and overwrites earlier sharing with the user. Each device can be simultaneously shared with up to 20 users.

This API method will soon be deprecated. Replace it with addDeviceShareWithRequestModel:success:failure:.

API description

-(void)addShareWithHomeId:homeId
            countryCode:countryCode
            userAccount:userAccount
                devIds:(NSArray<NSString *> *) success
                failure:(nullable ThingFailureError)failure;

Parameters

Parameter Description
homeId The ID of the home to which the devices belong.
countryCode The country code of the user who receives a sharing invitation.
userAccount The account of the user who receives a sharing invitation.
devIds The list of device IDs for sharing.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)addMemberShare {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare addShareWithHomeId:homeId countryCode:@"your_country_code" userAccount:@"user_account" devIds:(NSArray<NSString *> *) success:^(ThingSmartShareMemberModel *model) {
    NSLog(@"addShare success");
} failure:^(NSError *error) {
    NSLog(@"addShare failure: %@", error);
}];
}

Swift:

func addMemberShare() {
deviceShare?.add(withHomeId: homeId, countryCode: "your_country_code", userAccount: "user_account", devIds: ["devIds"], success: { (memberModel) in
    print("addShare success")
}, failure: { (error) in
    if let e = error {
        print("addShare failure: \(e)")
    }
})
}

(Legacy) Share a device

Shares a single device to a specific user and adds the device following earlier sharing with the user.

This API method will soon be deprecated. Replace it with addDeviceShareWithRequestModel:success:failure:.

API description

- (void)addDeviceShareWithHomeId:(long long)homeId
                    countryCode:(NSString *)countryCode
                    userAccount:(NSString *)userAccount
                        devId:(NSString *)devId
                        success:(void(^)(ThingSmartShareMemberModel *model))success
                        failure:(ThingFailureError)failure;

Parameters

Parameter Description
homeId The ID of the home to which the device belongs.
countryCode The country code of the user who receives a sharing invitation.
userAccount The account of the user who receives a sharing invitation.
devId The device ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)addDeviceShare {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare addDeviceShareWithHomeId:homeId countryCode:@"country_code" userAccount:@"user_account" devId:@"dev_id" success:^(ThingSmartShareMemberModel *model) {

    NSLog(@"addDeviceShare success");

} failure:^(NSError *error) {

    NSLog(@"addDeviceShare failure: %@", error);

}];

}

Swift:

func addDeviceShare() {
deviceShare?.add(withHomeId: homeId, countryCode: "country_code", userAccount: "user_account", devId: "dev_id", success: { (model) in
    print("addDeviceShare success")
}, failure: { (error) in
    if let e = error {
        print("addDeviceShare failure: \(e)")
    }
})
}

Query sharing relationships

Query all users who receive sharing invitations

API description

- (void)getReceiveMemberListWithSuccess:(void(^)(NSArray<ThingSmartShareMemberModel *> *list))success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getReceiveMemberList {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getReceiveMemberListWithSuccess:^(NSArray<ThingSmartShareMemberModel *> *list) {

    NSLog(@"getReceiveMemberList success");

} failure:^(NSError *error) {

    NSLog(@"getReceiveMemberList failure: %@", error);

}];
}

Swift:

func getReceiveMemberList() {
deviceShare?.getReceiveMemberList(success: { (list) in
    print("getReceiveMemberList success")
}, failure: { (error) in
    if let e = error {
        print("getReceiveMemberList failure: \(e)")
    }
})
}

Query all users who initiate sharing invitations in a home

The API method getShareMemberListWithHomeId:success:failure: will soon be deprecated. We recommend that you timely update the API.

API description

- (void)getShareMemberListWithSpaceId:(long long)spaceId
                            success:(void(^)(NSArray<ThingSmartShareMemberModel *> *list))success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
spaceId The ID of a specified space.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getShareMemberList {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getShareMemberListWithSpaceId:homeId success:^(NSArray<ThingSmartShareMemberModel *> *list)

    NSLog(@"getShareMemberList success");

} failure:^(NSError *error) {

    NSLog(@"getShareMemberList failure: %@", error);

}];

}

Swift:

func getShareMemberList() {
deviceShare?.getMemberList(withSpaceId: homeId, success: { (list) in
    print("getShareMemberList success")
}, failure: { (error) in
    if let e = error {
        print("getShareMemberList failure: \(e)")
    }
})
}

(Legacy) Query all users who initiate sharing invitations in a home

The API method will soon be deprecated. Replace it with getShareMemberListWithSpaceId:success:failure:.

API description

- (void)getShareMemberListWithHomeId:(long long)homeId
                            success:(void(^)(NSArray<ThingSmartShareMemberModel *> *list))success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
homeId The home ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getShareMemberList {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getShareMemberListWithHomeId:homeId success:^(NSArray<ThingSmartShareMemberModel *> *list)

    NSLog(@"getShareMemberList success");

} failure:^(NSError *error) {

    NSLog(@"getShareMemberList failure: %@", error);

}];

}

Swift:

func getShareMemberList() {
deviceShare?.getMemberList(withHomeId: homeId, success: { (list) in
    print("getShareMemberList success")
}, failure: { (error) in
    if let e = error {
        print("getShareMemberList failure: \(e)")
    }
})
}

Query sharing details of a user who initiates a sharing invitation

API description

- (void)getShareMemberDetailWithMemberId:(NSInteger)memberId
                                success:(void(^)(ThingSmartShareMemberDetailModel *model))success
                                failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The user ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getShareMemberDetail {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getShareMemberDetailWithMemberId:memberId success:^(ThingSmartShareMemberDetailModel *model) {

    NSLog(@"getShareMemberDetail success");

} failure:^(NSError *error) {

    NSLog(@"getShareMemberDetail failure: %@", error);

}];

}

Swift:

func getShareMemberDetail() {
deviceShare?.getMemberDetail(withMemberId: memberId, success: { (model) in
    print("getShareMemberDetail success")
}, failure: { (error) in
    if let e = error {
        print("getShareMemberDetail failure: \(e)")
    }
})
}

Query sharing details of a user who receives a sharing invitation

API description

- (void)getReceiveMemberDetailWithMemberId:(NSInteger)memberId
                                success:(void(^)(ThingSmartReceiveMemberDetailModel *model))success
                                failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The ID of the user who receives the sharing invitation.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getReceiveMemberDetail {
//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getReceiveMemberDetailWithMemberId:memberId success:^(ThingSmartReceiveMemberDetailModel *model) {

    NSLog(@"getReceiveMemberDetail success");

} failure:^(NSError *error) {

    NSLog(@"getReceiveMemberDetail failure: %@", error);

}];

}

Swift:

func getReceiveMemberDetail() {
deviceShare?.getReceiveMemberDetail(withMemberId: memberId, success: { (model) in
    print("getReceiveMemberDetail success")
}, failure: { (error) in
    if let e = error {
        print("getReceiveMemberDetail failure: \(e)")
    }
})
}

Query a list of users who share a device

API description

- (void)getDeviceShareMemberListWithDevId:(NSString *)devId
                                success:(void(^)(NSArray<ThingSmartShareMemberModel *> *list))success
                                failure:(ThingFailureError)failure;

Parameters

Parameter Description
devId The device ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getDeviceShareMemberList {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getDeviceShareMemberListWithDevId:@"dev_id" success:^(NSArray<ThingSmartShareMemberModel *> *list) {

    NSLog(@"getDeviceShareMemberList success");

} failure:^(NSError *error) {

    NSLog(@"getDeviceShareMemberList failure: %@", error);

}];

}

Swift:

func getDeviceShareMemberList() {
deviceShare?.getMemberList(withDevId: "dev_id", success: { (model) in
    print("getDeviceShareMemberList success")
}, failure: { (error) in
    if let e = error {
        print("getDeviceShareMemberList failure: \(e)")
    }
})
}

Query the source of a shared device

API description

- (void)getShareInfoWithDevId:(NSString *)devId
                    success:(void(^)(ThingSmartReceivedShareUserModel *model))success
                    failure:(ThingFailureError)failure;

Parameters

Parameter Description
devId The device ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)getShareInfo {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

    [self.deviceShare getShareInfoWithDevId:@"dev_id" success:^(ThingSmartReceivedShareUserModel *model) {

    NSLog(@"get shareInfo success");

} failure:^(NSError *error) {

    NSLog(@"get shareInfo failure: %@", error);

}];

}

Swift:

func getShareInfo() {
deviceShare?.getInfoWithDevId("dev_id", success: { (model) in
    print("getShareInfo success")
}, failure: { (error) in
    if let e = error {
        print("getShareInfo failure: \(e)")
    }
})
}

Remove sharing mappings

Remove a user who initiates sharing invitations

Removes a user who initiates sharing invitations to delete all sharing relationships from the user based on memberId.

API description

- (void)removeShareMemberWithMemberId:(NSInteger)memberId
                            success:(ThingSuccessHandler)success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The user ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeShareMember {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare removeShareMemberWithMemberId:memberId success:^{

    NSLog(@"removeShareMember success");

} failure:^(NSError *error) {

    NSLog(@"removeShareMember failure: %@", error);

}];

}

Swift:

func removeShareMember() {
deviceShare?.removeMember(withMemberId: memberId, success: {
    print("removeShareMember success")
}, failure: { (error) in
    if let e = error {
        print("removeShareMember failure: \(e)")
    }
})
}

Remove a user who receives sharing invitations

Removes a user that receives sharing invitations to delete all shared device information from the user based on memberId.

API description

- (void)removeReceiveShareMemberWithMemberId:(NSInteger)memberId
                                    success:(ThingSuccessHandler)success
                                    failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The ID of the user who receives the sharing invitations.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeReceiveMember {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare removeReceiveShareMemberWithMemberId:memberId success:^{

    NSLog(@"removeReceiveMember success");

} failure:^(NSError *error) {

    NSLog(@"removeReceiveMember failure: %@", error);

}];

}

Swift:

func removeReceiveMember() {
deviceShare?.removeReceiveMember(withMemberId: memberId, success: {
    print("removeReceiveMember success")
}, failure: { (error) in
    if let e = error {
        print("removeReceiveMember failure: \(e)")
    }
})
}

Remove a shared device

API description

- (void)removeDeviceShareWithMemberId:(NSInteger)memberId
                            devId:(NSString *)devId
                            success:(ThingSuccessHandler)success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The user ID.
devId The device ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeDeviceShare {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare removeDeviceShareWithMemberId:memberId devId:@"dev_id" success:^{

    NSLog(@"removeDeviceShare success");

} failure:^(NSError *error) {

    NSLog(@"removeDeviceShare failure: %@", error);

}];

}

Swift:

func removeDeviceShare() {
deviceShare?.remove(withMemberId: memberId, devId: "dev_id", success: {
    print("removeDeviceShare success")
}, failure: { (error) in
    if let e = error {
        print("removeDeviceShare failure: \(e)")
    }
})
}

Remove a received shared device

API description

- (void)removeReceiveDeviceShareWithDevId:(NSString *)devId
                                success:(ThingSuccessHandler)success
                                failure:(ThingFailureError)failure;

Parameters

Parameter Description
devId The device ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)removeDeviceShare {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare removeReceiveDeviceShareWithDevId:@"dev_id" success:^{

    NSLog(@"removeDeviceShare success");

} failure:^(NSError *error) {

    NSLog(@"removeDeviceShare failure: %@", error);

}];

}

Swift:

func removeDeviceShare() {
deviceShare?.removeReceive(withDevId: "dev_id", success: {
    print("removeDeviceShare success")
}, failure: { (error) in
    if let e = error {
        print("removeDeviceShare failure: \(e)")
    }
})
}

Change nicknames

Change nickname of a user who initiates sharing invitations

API description

- (void)renameShareMemberNameWithMemberId:(NSInteger)memberId
                                    name:(NSString *)name
                                success:(ThingSuccessHandler)success
                                failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The user ID.
name The new nickname of the user who initiates the sharing invitations.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)updateShareMemberName {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare renameShareMemberNameWithMemberId:memberId name:@"new_name" success:^{

    NSLog(@"updateShareMemberName success");

} failure:^(NSError *error) {

    NSLog(@"updateShareMemberName failure: %@", error);

}];

Swift:

func updateShareMemberName() {
deviceShare?.renameShareMemberName(withMemberId: "memberId", name: "new_name", success: {
    print("updateShareMemberName success")
}, failure: { (error) in
    if let e = error {
        print("updateShareMemberName failure: \(e)")
    }
})
}

Change nickname of a user who receives sharing invitations

API description

- (void)renameReceiveShareMemberNameWithMemberId:(NSInteger)memberId
                                        name:(NSString *)name
                                        success:(ThingSuccessHandler)success
                                        failure:(ThingFailureError)failure;

Parameters

Parameter Description
memberId The ID of the user who initiates sharing invitations.
name The new nickname.
success The success callback.
failure The failure callback.

Example

Objective-C:

- (void)updateReceiveMemberName {
    //self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare renameReceiveShareMemberNameWithMemberId:memberId name:@"new_name" success:^{

    NSLog(@"updateReceiveMemberName success");

} failure:^(NSError *error) {

    NSLog(@"updateReceiveMemberName failure: %@", error);

}];
}

Swift:

func updateReceiveMemberName() {
deviceShare?.renameReceiveMemberName(withMemberId: memberId, name: "new_name", success: {
    print("updateReceiveMemberName success")
}, failure: { (error) in
    if let e = error {
        print("updateReceiveMemberName failure: \(e)")
    }
})
}

Initiate device sharing invitations

Initiate device sharing with another user

API description

- (void)inviteShareWithCountryCode:(NSString *)countryCode
                    userAccount:(NSString *)userAccount
                            devId:(NSString *)devId
                        success:(ThingSuccessInt)success
                        failure:(ThingFailureError)failure;

Parameters

Parameter Description
countryCode The country code.
userAccount The user account.
devId The device ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

//self.deviceShare  = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare inviteShareWithCountryCode:Country code userAccount:Target user account devId: List of shared device IDs success:^(int result) {
    //do something
} failure:^(NSError *error) {
    //do something
}];

Swift:

deviceShare.invite(withCountryCode: Country code, userAccount: Target user account, devId: List of shared device IDs) { (_) in
    //do something
} failure: { (_) in
    //do something
}

Confirm a sharing invitation

API description

- (void)confirmInviteShareWithShareId:(NSInteger)shareId
                            success:(ThingSuccessHandler)success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
shareId The sharing invitation ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

//self.deviceShare = [[ThingSmartHomeDeviceShare alloc] init];
[self.deviceShare confirmInviteShareWithShareId: Sharing invitation ID success:^{
    //do something
} failure:^(NSError *error) {
    //do something
}];

Swift:

deviceShare.confirmInviteShare(withShareId: Sharing invitation ID) {
    //do something
} failure: { (_) in
    //do something
}

Share a device group

Query a list of users who share devices by group ID

The group ID appears on the device panel.

API description

- (void)getGroupShareMemberListWithGroupId:(NSString *)groupId
                                success:(void(^)(NSArray<ThingSmartShareMemberModel *> *list))success
                                failure:(ThingFailureError)failure;

Parameters

Parameter Description
groupId The group ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

//self.deviceShare = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare getGroupShareMemberListWithGroupId:Group ID success:^(NSArray<ThingSmartShareMemberModel *> * _Nonnull list) {
    //do something
} failure:^(NSError *error) {
    //do something
}];

Swift:

deviceShare.getGroupShareMemberList(withGroupId: Group ID) { (_) in
    //do something
} failure: { (_) in
    //do something
}

Add a user to a sharing group

API description

- (void)addGroupShareToMemberWithSpaceId:(long long)spaceId
                            countyCode:(NSString *)countryCode
                        userAccount:(NSString *)userAccount
                            groupId:(NSString *)groupId
                            success:(ThingSuccessID)success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
spaceId The ID of a specified space.
countryCode The country code.
userAccount The user account.
groupId The group ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

//self.deviceShare = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare addGroupShareToMemberWithSpaceId: Space ID countyCode: Country code userAccount: Target user account groupId: Group ID success:^(id result) {
    //do something
} failure:^(NSError *error) {
    //do something
}];

Swift:

deviceShare.addGroupShareToMember(withSpaceId: Space ID, countyCode: Country code, userAccount: Target user account, groupId: Group ID) { (_) in
    //do something
} failure: { (_) in
    //do something
}

Remove a user from a sharing group

API description

- (void)removeGroupShareWithRelationId:(NSInteger)relationId
                            groupId:(NSString *)groupId
                            success:(ThingSuccessHandler)success
                            failure:(ThingFailureError)failure;

Parameters

Parameter Description
relationId The user ID.
groupId The group ID.
success The success callback.
failure The failure callback.

Example

Objective-C:

//self.deviceShare = [[ThingSmartHomeDeviceShare alloc] init];

[self.deviceShare removeGroupShareWithRelationId: User ID groupId: Group ID success:^{
    //do something
} failure:^(NSError *error) {
    //do something
}];

Swift:

deviceShare.removeGroupShare(withRelationId: User ID, groupId: Group ID) {
    //do something
} failure: { (_) in
    //do something
}