iOS


This section explains the configuration and initialization effort required for SDK integration of iOS game. After complete the efforts described in this section, please continue the integration effort for other function module.

1.Setting Up the Development Environment

2.SDK Runtime Event Handling

3.Points to be Aware

3.1.Common Build issues

3.2.Supports for iOS 9.0

3.3.Supports for iOS version below 7.0

3.4.Supports for iOS 10.0

3.5 KTplay Window Orientation

1. Setting Up the Development Environment

Step 1. Download iOS SDK

  • Download and unzip ktplay_ios_sdk_xx_vx.x.x.zip into folder ktplay_ios_sdk_xx_vx.x.x

Step 2. Setup XCODE project configuration

To simplify the configuration, a script ./apply2xcode.sh will add required Framework and Other Link Flags to the game's XCODE project. The configuration process of using the script is listed as below

  • In folder ktplay_ios_sdk_vx.x.x/Utils , open "Terminal", and run ./apply2xcode.sh ${your game project file}

  • Game project file will setup required KTplay SDK configuration for Game's XCODE project

  • KTPlay SDK's depending Framework and Other Link Flags can be checked under Terminal's log

Step 3. Add KTplay SDK

  • Add downloaded KTplay SDK onto game's Xcode project.

2. SDK Runtime Event Handling

The runtime event concerned here is Initialization

#import "KTPlay.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // Override point for customization after application launch.
    KTPlay startWithAppKey:@"2na1elK" appSecret:@"3e8bbe12d983b8d1cdc174f49d7a8448613af078"];
    
    //...
    
    return YES;
    
}

3. Points to be Aware

3.1 Common Build issues

  • Duplicated 3rd party libraries, If there is build conflict due to duplicated libraries, please remove the duplicated libraries from KTPlaySDK/Libraries.

  • Other Linker Flags KTPlay apply2xcode.sh script will add -ObjC to Other Linker Flags, if this cause build error, then please remove -ObjC, and use one of the following flag, -all_load -force_load KTPlay/Plugins required libraries.

3.2 Enable http connection (iOS 9.0 support)

In iOS 9.0, http request will be converted to https by default. Since KTplay SDK still use http for some operation, it is necessary to enable http support in iOS9, and here are the steps required.

  • Open project's info.plist (Open As Property List)

  • Add NSAppTransportSecurity type Dictionary, if there not already have this item

  • Add NSAppTransportSecurity: NSAllowsArbitraryLoads, typeBoolean, valueYES.

The following is an example of modified info.plist (Open As Source Code).

    <key>NSAppTransportSecurity</key>

    <dict>
    
        <key>NSAllowsArbitraryLoads</key>
    
    <true/>
    
    </dict>

3.3 Supports for iOS version below 7.0

KTplay SDK will only run on iOS 7.0 or above, and it also use some of iOS framework that not compatible to older iOS version.
Although KTplay SDK will be disabled by itself when run on not supported OS version, it is required to make sure those incompatible iOS frameworks are set as Optional.

The following are Frameworks needed to set as Optional:

  • UIKit.framework

  • Foundation.framework

  • CoreFoundation.framework

  • Photo.framework

  • CoreTelephony.framework

iOS Framework listing

From your XCODE project's Target, Build Phase - Link Binary With Libraries, locate those Frameworks, and set them to Optional

3.4 Privacy

NSPhotoLibraryUsageDescription

From Apple's announcement, To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses the user’s photo library,must statically declare the intent to do so. Include the NSPhotoLibraryUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access the user’s photo library without a corresponding purpose string, your app exits.

  • Open project's info.plist (Open As Property List)
  • Add new field NSPhotoLibraryUsageDescription as String, and set value to following content:
    Allow access your photos so you can share them with other players.

The following is an example of modified info.plist (Open As Source Code).

    <key>NSPhotoLibraryUsageDescription</key>
    <string>Allow access your photos so you can share them with other players.</string>

NSPhotoLibraryAddUsageDescription

Important: To protect user privacy, an iOS app linked on or after iOS 11(Xcode9), and that seeks write-only access to the user’s photo library, must statically declare the intent to do so. Include the NSPhotoLibraryAddUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access the user’s photo library without a corresponding purpose string, your app exits. [https://developer.apple.com/library/prerelease/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html]

  • Open project's info.plist (Open As Property List)
  • Add new field NSPhotoLibraryAddUsageDescription as String, and set value to following content:
    Allow access your album to save photos.

The following is an example of modified info.plist (Open As Source Code).

    <key>NSPhotoLibraryAddUsageDescription</key>
  <string>Allow access your album to save photos.</string>

3.5 KTplay Window Orientation

  • Open project's info.plist (Open As Property List)

    • Add ktplay_config type Dictionary, if there not already have this item

    • Add ktplay_config: lock_orientation, typeString, valuelandscape or portrait.

Source Code

<key>ktplay_config</key>
<dict>
     <key>lock_orientation</key>
     <string>portrait</string>
</dict>
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.