Last Updated on : 2024-05-28 03:21:47download
This topic describes user services, allowing you to access login information and log in or out of a user account.
IUser methods
Method | Description |
---|---|
getUserId(): String | The unique identifier of the user. |
getUserName(): String | The name of the user. |
getSpaceType(): Int | The current space system.
|
Example
let user = UserService.shared().user()
- (void)loginWithParams:(NSDictionary *)params
success:(void(^)(void))success
failure:(void(^)(NSError *))failure;
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
params | NSDictionary | Yes | Parameters
|
success | (() -> Void)? | No | The success callback. |
failure | ((Error) -> Void)? | No | The failure callback. |
Example
let params = [
"username": "your account",
"password": "your password",
"projectCode": AppKey.projectCode,
]
UserService.shared().login(withParams: params) {
printf("success")
} failure: { error in
printf("error")
}
- (void)logoutSuccess:(void(^)(void))success
failure:(void(^)(NSError *))failure;
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
success | (() -> Void)? | No | The success callback. |
failure | ((Error) -> Void)? | No | The failure callback. |
Example
UserService.shared().logoutSuccess {
printf("success")
} failure: { error in
printf("error")
}
- (void)getUserDetailWithParams:(NSDictionary *_Nullable)params
success:(void(^)(NSDictionary *))success
failure:(void(^)(NSError *))failure
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
params | NSDictionary | No | Parameters |
success | (() -> Void)? | No | The success callback. |
failure | ((Error) -> Void)? | No | The failure callback. |
Example
UserService.shared().getUserDetail(withParams: nil, success: { userDetails in
print("User details: \(userDetails)")
} failure: { error in
print("Error: \(error.localizedDescription)")
})
Example
if (let isLogin = UserService.shared().user()?.isLogin()) {
print("login state")
} else {
print("no login")
}
After you register a listener for login session expiration, this callback will be triggered when the user changes their password or remains inactive for a period. A successful callback indicates that the login has expired and prompts the user to log in again.
Example
import IndustryAuthKit
// Adding an observer for the login notification
NotificationCenter.default.addObserver(
self,
selector: #selector(loginAction),
name: NSNotification.Name("industryAuthKitDidAuth"),
object: nil)
// Adding an observer for the logout notification
NotificationCenter.default.addObserver(
self,
selector: #selector(logoutAction),
name: NSNotification.Name("industryAuthKitDidUnauth"),
object: nil)
// Adding an observer for the logout notification due to invalid authentication
NotificationCenter.default.addObserver(
self,
selector: #selector(logoutAction),
name: NSNotification.Name("industryAuthKitAuthDidInvalid"),
object: nil)
@objc func loginAction() {
// Handle login
print("Logged in successfully")
}
@objc func logoutAction() {
// Handle logout
print("Logged out successfully or session invalidated")
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback