Last Updated on : 2022-03-03 06:49:29
A user can share a device on a site with other users on the same site so that the other users can control the device. The users that receive a sharing invitation can control the device by using their app account.
Class name | Description |
---|---|
TuyaSmartHomeDeviceShare | Provides the capabilities to share devices. |
ObjC:
#import <TuyaSmartDeviceKit/TuyaSmartHomeDeviceShare.h>
Swift:
import TuyaSmartDeviceKit
Shares one or more devices with a specific user.
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:(TuyaSmartDeviceShareRequestModel *)requestModel
success:(void(^)(TuyaSmartShareMemberModel *model))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
requestModel | The request object. |
success | The success callback. |
failure | The failure callback. |
TuyaSmartDeviceShareRequestModel
@interface TuyaSmartDeviceShareRequestModel : NSObject
/// The ID of the site to which the shared devices belong.
@property (nonatomic, assign) long long homeID;
/// The country code of the user that receives a sharing invitation.
@property (nonatomic, copy) NSString *countryCode;
/// The account of the user that receives a sharing invitation.
@property (nonatomic, copy) NSString *userAccount;
/// The list of device IDs for sharing.
@property (nonatomic, copy) NSArray<NSString *> *devIds;
@end
Example
ObjC:
- (void)addMemberShare {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
TuyaSmartDeviceShareRequestModel *model = [TuyaSmartDeviceShareRequestModel new];
model.homeID = Site ID;
model.countryCode = Country code;
model.userAccount = Target user account;
model.devIds = List of shared device IDs;
[self.deviceShare addDeviceShareWithRequestModel:model success:^(TuyaSmartShareMemberModel * _Nonnull model) {
//do something
} failure:^(NSError *error) {
//do something
}];
}
Swift:
func addMemberShare() {
var model = TuyaSmartDeviceShareRequestModel.init()
model.homeID = Site 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
}
}
Shares multiple devices to a specific user and adds these devices following earlier sharing with the user.
API description
- (void)addShareWithMemberId:(NSInteger)memberId
devIds:(NSArray <NSString *> *)devIds
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The ID of the user that receives a sharing invitation. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)addMemberShare {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
Shares multiple devices to a specific user and overwrite earlier sharing with the user.
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 TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
homeId | The site ID with which the device is associated. |
countryCode | The country code of the user that receives a sharing invitation. |
userAccount | The account of the user that receives a sharing invitation. |
devIds | The list of device IDs for sharing. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)addMemberShare {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare addShareWithHomeId:homeId countryCode:@"your_country_code" userAccount:@"user_account" devIds:(NSArray<NSString *> *) success:^(TuyaSmartShareMemberModel *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)")
}
})
}
Shares a single device to a specific user and adds the devices 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(^)(TuyaSmartShareMemberModel *model))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
homeId | The site ID. |
countryCode | The country code of the user that receives a sharing invitation. |
userAccount | The account of the user that receives a sharing invitation. |
devId | The device ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)addDeviceShare {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare addDeviceShareWithHomeId:homeId countryCode:@"country_code" userAccount:@"user_account" devId:@"dev_id" success:^(TuyaSmartShareMemberModel *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)")
}
})
}
API description
- (void)getReceiveMemberListWithSuccess:(void(^)(NSArray<TuyaSmartShareMemberModel *> *list))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getReceiveMemberList {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getReceiveMemberListWithSuccess:^(NSArray<TuyaSmartShareMemberModel *> *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)")
}
})
}
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<TuyaSmartShareMemberModel *> *list))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
spaceId | The ID of a specified space. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getShareMemberList {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getShareMemberListWithSpaceId:homeId success:^(NSArray<TuyaSmartShareMemberModel *> *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)")
}
})
}
The API method will soon be deprecated. Replace it with getShareMemberListWithSpaceId:success:failure:
.
API description
- (void)getShareMemberListWithHomeId:(long long)homeId
success:(void(^)(NSArray<TuyaSmartShareMemberModel *> *list))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
homeId | |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getShareMemberList {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getShareMemberListWithHomeId:homeId success:^(NSArray<TuyaSmartShareMemberModel *> *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)")
}
})
}
API description
- (void)getShareMemberDetailWithMemberId:(NSInteger)memberId
success:(void(^)(TuyaSmartShareMemberDetailModel *model))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The user ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getShareMemberDetail {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getShareMemberDetailWithMemberId:memberId success:^(TuyaSmartShareMemberDetailModel *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)")
}
})
}
API description
- (void)getReceiveMemberDetailWithMemberId:(NSInteger)memberId
success:(void(^)(TuyaSmartReceiveMemberDetailModel *model))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The ID of the user that receives the sharing invitation |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getReceiveMemberDetail {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getReceiveMemberDetailWithMemberId:memberId success:^(TuyaSmartReceiveMemberDetailModel *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)")
}
})
}
API description
- (void)getDeviceShareMemberListWithDevId:(NSString *)devId
success:(void(^)(NSArray<TuyaSmartShareMemberModel *> *list))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
devId | The device ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getDeviceShareMemberList {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getDeviceShareMemberListWithDevId:@"dev_id" success:^(NSArray<TuyaSmartShareMemberModel *> *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)")
}
})
}
API description
- (void)getShareInfoWithDevId:(NSString *)devId
success:(void(^)(TuyaSmartReceivedShareUserModel *model))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
devId | The device ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)getShareInfo {
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getShareInfoWithDevId:@"dev_id" success:^(TuyaSmartReceivedShareUserModel *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)")
}
})
}
Removes a user that initiates sharing invitations to delete all sharing relationships from the user based on memberId
.
API description
- (void)removeShareMemberWithMemberId:(NSInteger)memberId
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The user ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)removeShareMember {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
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:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The ID of the user that receives the sharing invitations. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)removeReceiveMember {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
API description
- (void)removeDeviceShareWithMemberId:(NSInteger)memberId
devId:(NSString *)devId
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The user ID. |
devId | The device ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)removeDeviceShare {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
API description
- (void)removeReceiveDeviceShareWithDevId:(NSString *)devId
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
devId | The device ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)removeDeviceShare {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
API description
- (void)renameShareMemberNameWithMemberId:(NSInteger)memberId
name:(NSString *)name
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The user ID. |
name | The nickname of the user that initiates the sharing invitations. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)updateShareMemberName {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
API description
- (void)renameReceiveShareMemberNameWithMemberId:(NSInteger)memberId
name:(NSString *)name
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
memberId | The ID of the user that initiates sharing invitations. |
name | The new nickname. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
- (void)updateReceiveMemberName {
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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)")
}
})
}
API description
- (void)inviteShareWithCountryCode:(NSString *)countryCode
userAccount:(NSString *)userAccount
devId:(NSString *)devId
success:(TYSuccessInt)success
failure:(TYFailureError)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
ObjC:
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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
}
API description
- (void)confirmInviteShareWithShareId:(NSInteger)shareId
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
shareId | The sharing ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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
}
The group ID appears on the device panel.
API description
- (void)getGroupShareMemberListWithGroupId:(NSString *)groupId
success:(void(^)(NSArray<TuyaSmartShareMemberModel *> *list))success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
groupId | The group ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
//self.deviceShare = [[TuyaSmartHomeDeviceShare alloc] init];
[self.deviceShare getGroupShareMemberListWithGroupId: Group ID success:^(NSArray<TuyaSmartShareMemberModel *> * _Nonnull list) {
//do something
} failure:^(NSError *error) {
//do something
}];
Swift:
deviceShare.getGroupShareMemberList(withGroupId: Group ID) { (_) in
//do something
} failure: { (_) in
//do something
}
API description
- (void)addGroupShareToMemberWithSpaceId:(long long)spaceId
countyCode:(NSString *)countryCode
userAccount:(NSString *)userAccount
groupId:(NSString *)groupId
success:(TYSuccessID)success
failure:(TYFailureError)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
ObjC:
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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
}
API description
- (void)removeGroupShareWithRelationId:(NSInteger)relationId
groupId:(NSString *)groupId
success:(TYSuccessHandler)success
failure:(TYFailureError)failure;
Parameters
Parameter | Description |
---|---|
relationId | The member ID. |
groupId | The group ID. |
success | The success callback. |
failure | The failure callback. |
Example
ObjC:
//self.deviceShare = [[TuyaSmartHomeDeviceShare 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
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback