This topic describes how to use Xcode to integrate GameShield SDK for iOS.

Prerequisites

The SDK package and AccessKey for iOS is obtained from the GameShield console. The AccessKey is required when you set the appkey parameter. For more information, see Obtain an SDK package and AccessKey pair. Obtain the SDK package and AccessKey

Procedure

  1. Open Xcode.
  2. Create a project, select Single View Application, and then use the default settings to complete the creation of the project. In this example, the project is named yxd_sdk_test.
    Note Before you perform the next steps, you must ensure that the new project is running normally.
  3. Add dependencies. Copy the YunCeng.framework file from the iOS SDK package to the directory where the new project resides. In this example, the project is yxd_sdk_test. Copy YunCeng.framework
  4. Modify the project settings.
    • Change Build Phases to Link Binary With Libraries.
    • Add the YunCeng.framework file and its associated frameworks. Add YunCeng.framework
  5. Initialize the SDK.
    Before you run the following code, you must replace the following variables:
    • Replace <yourAppKey> with the AccessKey that you obtained in the GameShield console.
    • Replace <token> with the unique ID of a player in your game. If the ID is unavailable, you can use the default value. You cannot leave <token> unspecified.
    - (int) SDKInit {
        const char * appkey = "<yourAppKey>";
        const char * token = "<token>";
        int ret = YunCeng_InitEx(appkey, token);
        if (ret == 0) {
            NSLog(@"sdk init success");
        } else {
            NSLog(@"sdk init failed, ret %d", ret);
        }
        return ret;
    }
    Troubleshooting:
    • If the "_OBJC_CLASS_$_CTTelephonyNetworkInfo", referenced from error message appears when you compile the code, we recommend that you add the CoreTelephony.framework library. For more information, see Step 4.
    • If the "_res_9_getservers", referenced from error message appears when you compile the code, we recommend that you add the libresolv.tbd library. For more information, see Step 4. libresolv.tbd

What to do next

After you add your application, you can use the SDK to retrieve the IP address and the port that are mapped by GameShield for your application. The method that GameShield uses to map an IP address and a port for your application varies based on your service type. For details about the methods, see the following topics: