iOS SDK_安装及环境配置

安装GAMEPOT iOS SDK后配置环境并关联GAMEPOT仪表盘和游戏,即可使用游戏开发所需的功能。

GamePod SDK中的支援語言如下。

  • 英語、意大利語、泰語、越南語、日語、漢語(簡體/繁體)、印度尼西亞語、德語、西班牙語、法語和韓語

應用程序運行時,根據機器設備的語言,在SDK內標記爲支援語言,未支援語言用英語標記。需要添加想要應用於 xcode > on的語言。

Buildi版本代碼請以整數形態獨特增加的方式進行。

安装SDK


安装GAMEPOT iOS SDK后,在Xcode中配置项目的方法如下。

  1. 请使用管理员账户登录仪表盘。

  2. 依次点击下载SDK > iOS菜单后点击下载

  3. 运行Xcode后,开启游戏项目。

  4. 解压下载的SDK文件后,拖放至已创建的项目文件夹。

添加Dependencies及Bundle Resource


为使用SDK,如要在Xcode中按各类服务添加合适的Dependencies及Bundle Resource,请参考下表。

Service

Framework

Dependencies

Bundle Resource

基本(Base)

AFNetworking.framework

FirebaseAnalytics.framework

FirebaseCore.framework

FirebaseCoreDiagnostics.framework

FirebaseInstanceID.framework

FirebaseMessaging.framework

FirebaseNanoPB.framework

GamePot.framework

GoogleToolboxForMac.framework

nanopb.framework

Protobuf.framework

libz.tbd

WebKit.framework

UserNotifications.framework

GamePot.bundle

登录(Login)

Base

GamePotChannel.framework

Google Sign In

GamePotGoogleSignIn.framework

GoogleSignIn.framework

GoogleSignInDependencies.framework

Facebook

FBAEMKit.xcframework

FBSDKCoreKit_Basics.xcframework

FBSDKCoreKit.xcframework

FBSDKLoginKit.xcframework

GamePotFacebook.framework

LINE

GamePotLine.framework

LineSDK.framework

LineSDKObjC.framework

NAVER

GamePotNaver.framework

NaverThirdPartyLogin.framework

Google Sign In

AuthenticationServices.framework

LocalAuthentication.framework

Facebook

SafariServices.framework

LINE

SafariServices.framework

Google Sign In

GoogleSignIn.bundle

GameCenter

GamePotGameCenter.framework

AppleID

GamePotApple.framework

添加并设置Information Property List


为使用SDK需将Information Property List添加到Xcode后进行设置。

由于GAMEPOT iOS SDK使用Google Firebase,因此除了包含SDK默认值的Information Property List以外,同时要在项目中添加从Firebase控制台获取的Information Property List。

添加并设置Information Property List的方法如下。

  1. 将下载的SDK文件中包含的GamePotConfig-Info.plist文件添加到项目中。

    • 如果相应文件不存在,请使用相同的名称创建文件后输入密钥对应的值。

  2. 将Google Firebase控制台中获取的GoogleService-Info.plist文件添加到项目中。

  3. 在Xcode添加的GamePotConfig-Info.plist中变更以下设置。

    • gamepot_project_id:GAMEPOT项目ID

    • gamepot_elsa_projectid:(可选) GAMEPOT日志项目ID

  4. 依次点击Targets > Info > Custom iOS Target Properties菜单后,添加以下用户权限获取选项。

    • 该用户权限在GAMEPOT客服中心内的文件上传功能中使用。 NSCameraUsageDescription, NSPhotoLibraryUsageDescription, NSMicrophoneUsageDescription

      • 从iOS 14版本开始,改成了获取IDFA值时必须向用户请求权限才能获取IDFA值。 因此,为了在获取IDFA值时使用向用户请求权限的弹窗, 请在Targets >> Info >> Custom iOS Target Properties中添加以下用户权限获取选项。 (必须添加关于收集目的与使用地点的说明。) NSUserTrackingUsageDescription

  5. 仅当GamePod仪表板生成区域为新加坡时,请添加以下设置。

    • gamepot_region: sg

  6. 仅当GamePod仪表板生成区域为日本时,请添加以下设置。

    • gamepot_license_url: https://gamepot.apigw.ntruss.com/fw/jp-v1

添加Build Settings选项


为使用SDK需在Xcode Build Settings添加-ObjC -lz -lstdc++ -lc++选项。

如要添加选项,在Xcode依次点击Build Settings > Linking > Other Linker Flags菜单后添加-ObjC -lz -lstdc++ -lc++选项。

设置登录环境


如要设置第三方账户的登录环境,需在Xcode项目添加合适的设置。

Facebook登录环境

如果已完成添加Dependencies,即可设置Facebook登录环境。

Facebook登录环境的设置方法如下。

  1. 在Facebook for Developers控制台将应用类型选择为NoneConsumerGaming后创建应用。

  2. 将Facebook App ID值以"fb{Facebook App ID}"格式添加到Xcode的Info > URL Types菜单(例:fb561593141718906)。

  3. 依次点击Info > iOS Target Property菜单后,在LSApplicationQueriesSchemes添加以下设置。

    • fbapi, fb-messenger-share-api, fbauth2, fbshareextension, fb-messenger-api

  4. 在GamePotConfig-Info.plist变更以下设置。

    • gamepot_facebook_app_id: Facebook App ID

    • gamepot_facebook_display_name: Facebook display name

    • gamepot_facebook_client_token: // Facebook 控制檯 > 應用程序 > 設置 > 高級設置 > 客戶端代幣


设置Google Sign In、LINE、NAVER、Apple ID登录环境

如果已完成添加Dependencies,即可设置第三方账户的登录环境。

如要设置第三方账户的登录环境,需在Xcode项目中添加以下设置。

  • Google Sign In

    • 复制GoogleService-Info.plist文件的REVERSED_CLIENT_ID值,在Xcode依次点击Info > URL Types菜单后添加项目,并在URL Schemes进行输入

    • 在GamePotConfig-Info.plist变更以下设置 gamepot_google_app_id:GoogleService-Info.plist文件的CLIENT_IDgamepot_google_url_schemes:GoogleService-Info.plist文件的REVERSED_CLIENT_ID

  • LINE

    • 在GamePotConfig-Info.plist变更以下设置 gamepot_line_channelid: Line Channel ID gamepot_line_url_schemes:LINE URL Scheme(line3rdp.{项目绑定ID})

      • 依次点击Info > iOS Target Property菜单后,在LSApplicationQueriesSchemes添加以下设置。 lineauth2

  • NAVER

    • 在GamePotConfig-Info.plist变更以下设置 gamepot_naver_clientid: Naver Client Id gamepot_naver_secretid: Naver Secret Id gamepot_naver_urlscheme: Naver URL Scheme

    • Info > iOS Target Property 菜单的LSApplicationQueriesSchemes添加以下设置 naversearchapp, naversearchthirdlogin, navercafe

    • Info > URL Types 菜单添加与gamepot_naver_urlscheme相同的值

  • Apple ID

    • 选择Target后在Signing & Capabilities菜单添加Sign In with Apple Capability

重置


如要执行重置,在AppDelegate文件使用以下代码。

#import <GamePot/GamePot.h>

#if __has_include(<AppTrackingTransparency/AppTrackingTransparency.h>)
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#endif


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    // GamePot SDK Initialize
    [[GamePot getInstance] setup];

    // Push Permission
    if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0"))
    {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
            if(!error){
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[UIApplication sharedApplication] registerForRemoteNotifications];
                });
            }
        }];
    }
    else
    {
        // Code for old versions
        UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
        [application registerUserNotificationSettings:settings];
        [application registerForRemoteNotifications];
    }

// 为在iOS 14版本导入IDFA值,调用权限请求弹窗
// 项目中未添加AppTrackingTransparency.framework时,无法调用。
#if __has_include(<AppTrackingTransparency/AppTrackingTransparency.h>)
   if (@available(iOS 14, *)) {
       if(NSClassFromString(@"ATTrackingManager"))
       {
           // 没有注册侦听器时,不会弹出请求弹窗。
           [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {

               switch (status)
               {
                   case ATTrackingManagerAuthorizationStatusNotDetermined:
                       break;
                   case ATTrackingManagerAuthorizationStatusRestricted:
                       break;
                   case ATTrackingManagerAuthorizationStatusDenied:
                       break;
                   case ATTrackingManagerAuthorizationStatusAuthorized:
                       break;
                   default:
                       break;
               }
           }];
       }
   }
#endif
    ...
}

 // Push
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    ...
    [[GamePot getInstance] handleRemoteNotificationsWithDeviceToken:deviceToken];
    ...
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [[GamePotChat getInstance] start];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [[GamePotChat getInstance] stop];
}

Last updated