Introduction

SG iOS SDK allows you to connect to SG backend services easily when developing iOS App using Swift.

It's important for you to read through and understand the document before starting development.

Development Environment

1.SDK minimum version requirement

  • Minimum iOS version: 9.0
  • Minimum Swift version: 4.0

2.Download SGSDK iOS framework

3.Sample application


4.SGSDK Framework(swift)


Copy SGSDK.framework to project folder

5.XCode settings


  1. In navigator area, select your project.
  2. From editor area, click General.
  3. Go down to Embedded Binaries section.
  4. Click +.
  5. Select Add Other....
  6. Copy SGSDK.framework then click Finish.
  7. You will see SGSDK.framework appeared in Embedded Binaries and Linked Frameworks sections.

6.Import SGSDK


In your Swift project, import SGSDK.

import SGSDK

Initialization

1.SGSDK Callback Listener

Function

SetListener(listener: @escaping (SGListenerResult) -> Void) -> Void

Description
  • In order to get the result of many SDK asynchronized functions, you need to register a Listener to handle the response data.
Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
SGSDK.Instance.SetListener(listener: MsgListener)

func MsgListener(result: SGListenerResult) {
    switch result.Code {
    case 201, 301, 1001, 801, 1501: // Login, Signup, Login by token
        break
    case 1101:  // SG server validating receipt ok
        break
    case 1136:  // appstore transaction ok
        break
    case 1141:  // Restore
        break
    case 1201:  // Get Order
        break
    case 8004:  // Open ID
        break
    default:
        break
    }
    //print("code: \(result.Code), msg: \(result.Msg)")
}

Parameters
  • SDK responses through SGListenerResult object, which contains three members: CodeMessage and Data. Based on different situation, Data might be NULL or an object. Please refer to each function for more detail.

2.SGSDK initialization

Function

Init(GameKey: String, AppSecret: String) -> Void

Description
  • Initialize SDK. You have to call Init function once before any other functions.
Parameters
  • GameKey
  • AppSecret
Response

Release Resource

Function

Destroy() -> Void

Description
  • Release SGSDK resource.