User System

User system is used to manage SG users, including signup, login and kids (family members ) management, etc. Most of the functions use WebView control as part of the process flow. To handle response of these functions, you need to register a callback listener to SGSDK.

Signup

Function

Signup() -> Void

Description
  • Launch [Signup] view.
  • After signing up, system logs user in automatically, and widget button is shown.
Response
iOS UI

Login

Function

Login() -> Void

Description
  • Launch [Login] view.
  • After successful login, widget button is shown.
Response
iOS UI iOS UI

Forget Password

Function

ForgotPassword() -> Void

Description
  • Launch [Forget Password] view.
Response
iOS UI

Change Password

Function

ChangePassword() -> Void

Description
  • Launch [Change Password] view.
Response
iOS UI

Parental Lock

Function

ParentalLock() -> Void

Description
  • Launch [Parental Lock] view.
  • You can use parental lock utility view before important actions.
Response
  • After successfully enter the code, it redirects to [My Account] page.
  • If the user haven't created any kid (family member), , it redirects to [My Kid] page.
iOS UI

My Kid

Function

MyKid() -> Void

Description
  • Launch [My Kid] view.
  • The flow is for creating new kid (family member) of the user.
Response
iOS UI

My Account

Function

MyAccount() -> Void

Description
  • Launch [My Account] view.
  • The flow is the entry page for managing kids (family members).
iOS UI

Verify Session

Function

VerifySession(gameKey: String, sessionId: String, openId: String, sign: String)

Description
  • Verify if current session ID is valid.
Parameters
gameKey Your developer identification.
openId SG member ID.
You can obtain it through GetOpenID() after user login.
sessionId Current session ID.
You can obtain it through GetSessionID() after user login.
sign Signature generated from above three parameters.
Please refer to signature algorithm.
Response

Login by Token

Function

LoginByToken(token: String) -> Void

Description
  • Login into the system by previously saved token.
Parameters
  • Token used for login.
    You can obtain it through GetToken() after user login.
Response

Other Functions

1.Get Open ID

Function

GetOpenID() -> String?

Description
  • Obtain Open ID (SG ID) after user login.
Example

1
2
3
4
5
if let msg = SGSDK.Instance.GetOpenID() {
    //print("msg")
} else {
    //print("Please login.")
}

Response
  • Return Open ID if successful, or nil if failed.

2.Get Session ID

Function

GetSessionID() -> String?

Description
  • Obtain Session ID after user login.
Example

1
2
3
4
5
if let msg = SGSDK.Instance.GetSessionID() {
    //print(msg)
} else {
    //print("Please login.")
}

Response
  • Return Session ID if successful, or nil if failed.

3.Get Token

Function

GetToken() -> String?

Description
  • Obtain Token after user login.
Example

1
2
3
4
5
if let msg = SGSDK.Instance.GetToken() {
    //print(msg)
} else {
    //print("Please login.")
}

Response
  • Return Token if successful, or nil if failed.

4.Get index of selected kid

Function

GetKidIndex() -> Int?

Description Response
  • Return index number if successful, or nil if failed.

5.Get face icon of selected kid

Function

GetKidFace() -> String?

Description Response
  • Return face icon if successful, or nil if failed.

6.Check login status

Function

IsLogin() -> Bool

Description
  • Check login status.
Response
  • Return true if login, or false if not.

7.Get Channel ID

Function

GetChannelID() -> String

Description
  • Obtain Channel ID.
Response

Widget

1.Show widget button

Function

ShowWidget(place: EWidgetLocation = .Left) -> Void

Description
  • Widget button is shown automatically after successful login or signup.
  • Click on widget button will launch My Account view.
Parameters

Enum : EWidgetLocation

Case Description
TopLeft Top left of the screen
Top Top of the screen
TopRight Top right of the screen
Left Left side of the screen
Right Right side of the screen
BottomLeft Bottom left of the screen
Bottom Bottom of the screen
BottomRight Bottom right of the screen

2.Hide widget button

Function

HideWidget() -> Void

Description
  • Hide widget button.

3.Check widget visibility

Function

IsWidgetVisible() -> Bool

Description
  • Check widget visibility.
Response
  • True if visible, or false if not.

Logout

Function

Logout() -> Void

Description
  • Log user out.
  • After successful logout, widget button is hidden automatically.
Response

WeChat Login

Function

WXApiResp(errCode: Int, code: String) -> Void

Description
  • WeChat Login.
  • Need prepare some file.
  • WeChat SDK files. (libWeChatSDK.a, WechatAuthSDK.h, WXApi.h, WXApiObject.h)
  • If project is Swift language should add header file [project name]-Bridging-Header.h and write #import "WXApi.h".
  • AppDelegate add WXApiDelegate protocol. (refer to WeChat SDK)
  • Override handleOpenURL and openURL.
  • Implement WXApiDelegate protocol two method.
Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {

    var window: UIWindow?
    
    public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return WXApi.handleOpen(url, delegate: self)
    }
    
    public func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
        return WXApi.handleOpen(url, delegate: self)
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        return true
    }

    func onResp(_ resp: BaseResp!) {
        if let authresp = resp as? SendAuthResp {
            SGSDK.Instance.WXApiResp(errCode: Int(resp.errCode), code: authresp.code)
        }
    }
    
    func onReq(_ req: BaseReq!) {
        
    }
}

Response