Skip to main content

User Relation

Create User Relation#

UserId is needed to make sure the purchase status appmate is tracking gets associated with the user you defined. You can also define relationships between different userIds. For example, you have a user who has two devices and he/she wants to use your app with both of them. If your user has some purchases that made with the first userId, also second userId will be able to see this products as purchased. Whenever there is a change in a user's entitlement to products within your app, the second device user also will be able to get this updates. It's easy to use this feature with appmate only by establishing relationships between the users.

master_sub_users

Here masterUserId is a userId value which you will relate with the current UserId.

Current userId is the value that you set with setUserId() method of PurchaseClient or the given parameter when creating an instance of PurchaseClient.

As you create a relationship between this masterUserId and current userId values, you can assume currentUserId as a subUserId here.

Request#

Parameter NameType
masterUserIdString
completion(CreateUserRelationResponse?, GenericError?) -> Void

Response#

Parameter NameType
responseCreateUserRelationResponse?
errorGenericError?
PurchaseClient.shared.createUserIdRelation(with: "masterUserId") { response, error in               if let response = response {        print(response)    } else {        print(error)    }}

With this feature the same user of our app, will be able to reach active purchase results by using your application installed both two devices.

Delete User Relation#

It's also possible to delete a relationship between the users. By giving subUserId as a parameter, you can use deleteSubUserIdRelation method and delete a relationship between subUserId and its master.

Request#

Parameter NameType
subUserIdString
completion(DeleteUserRelationResponse?, GenericError?) -> Void

Response#

Parameter NameType
responseDeleteUserRelationResponse?
errorGenericError?
PurchaseClient.shared.deleteSubUserIdRelation(for: "subUserId") { result in    switch result {    case .success(let response):        break    case .failure(let error):        break    }}

If you want to delete all the relationships related to the masterUserId, you can use deleteMasterUserIdRelation method by giving masterUserId as a parameter.

Request#

Parameter NameType
masterUserIdString
completion(DeleteUserRelationResponse?, GenericError?) -> Void

Response#

Parameter NameType
responseDeleteUserRelationResponse
errorGenericError?
PurchaseClient.shared.deleteMasterUserIdRelation(for: "masterUserId") { response, error in            if let response = response {        print(response)    } else {        print(error)    }}