Unity iOS
これはHive SDK Unity iOSアプリの構築と設定をガイドします。
Xcodeの署名と機能に権限を追加する¶
選択した機能を使用するために、Xcodeプロジェクトに権限を追加します Hive > ExternalDependency。Hive PostProcessエディタまたはHivePostProcess.csを使用して追加できます。
Hive ポストプロセスエディタを通じて追加¶
Unity開発環境からHive PostProcessエディタを実行するには、Hive > ビルドプロジェクトのポストプロセス設定 > iOSまたはHive > 設定を編集 > iOSプロジェクトのビルドポストプロセス設定に移動します。次に、希望するHive SDK機能を選択し、Xcodeの署名と機能セクションに権限を追加できます。
ここに追加できるHive SDKの機能があります:
- プッシュ通知: ローカルおよびリモートプッシュ機能を有効にします。- 開発モード: 開発用プロビジョニングプロファイル証明書を使用する際に設定します。
- リリースモード: リリース用プロビジョニングプロファイル証明書を使用する際に設定します。
 
- バックグラウンドモード (リモート通知): アプリがバックグラウンドにあるときにリモートプッシュ通知を受信するかどうかを決定します。
- Appleサインイン: Appleログイン機能を有効にします。
- 関連ドメイン: ユニバーサルリンクを許可するドメインのリスト(ウェブサイトからアプリをインストールおよび実行することを許可します)。
- アプリ内購入: アプリ内購入機能を有効にします。
- ゲームセンター: ゲームセンターのログインおよび関連機能を有効にします。 
選択した機能をXcodeの署名と機能に追加するには適用をクリックしてください。設定をデフォルト値にリセットするにはリセットをクリックしてください。
設定された値は、Assets > Hive_SDK_v4 > PostProcess > iOS > HivePostProcessSettingIOS.txtにJSON文字列として保存されます。 
Note
Hive PostProcess Editorを使用せずに、HivePostProcessSettingiOS.txtファイルの内容を直接編集することで、Xcodeプロジェクトの機能を変更することもできます。
HivePostProcess.csを通じて追加する¶
UnityでXcodeプロジェクトをビルドする前に、HivePostProcess.csファイル内のコードのコメントを解除すると、Hive SDK機能の権限が自動的にXcodeの署名と機能に追加されます。コードをコメントアウトすると、権限が削除されます。
以下のコードの特定の行をコメントアウトすると、対応する権限が「署名と機能」に追加されるのを防ぎます。使用するつもりのない権限については、コードをコメントアウトすることをお勧めします。
private static void iOSSettingCapabilites(string path, HivePostProcessSettingIOS setting) {
   #if UNITY_IOS
   Debug.Log("iOSSettingCapabilites : OnPostProcessBuild -\n path: "+path);
   var projPath = PBXProject.GetPBXProjectPath(path);
   var mainTargetName = "Unity-iPhone";
   var entitlementsFileName = "Entitlements.entitlements";
   ProjectCapabilityManager capabilityManager = new ProjectCapabilityManager(projPath, entitlementsFileName, mainTargetName);
    if (setting.isAddInAppPurchase) {
       capabilityManager.AddInAppPurchase();
   }
    if (setting.isAddPushNotifications) {
       // If you don't use push notification (Hive SDK notification) feature, comment out the line below.
       capabilityManager.AddPushNotifications(setting.isPushNotificationsDevelopment);
   }
    if (setting.isAddBackGroundModesRemoteNotifications) {
       capabilityManager.AddBackgroundModes(iOS.Xcode.BackgroundModesOptions.RemoteNotifications);
   }
    if (setting.isAddSignInWithApple) {
       // If you don't use Sign In With Apple feature, comment out the line below.
       capabilityManager.AddSignInWithApple();
   }
    if (setting.isAddAssociatedDomains) {
       var associatedDomains = setting.associatedDomains;
       capabilityManager.AddAssociatedDomains(associatedDomains.ToArray());
   }
    capabilityManager.WriteToFile();
   if (setting.isAddGameCenter) {
       var entitlementsModifier = new HiveEntitlementsModifier(path, entitlementsFileName);
       entitlementsModifier.AddGameCenter();
   }
   #endif
}
Warning
HivePostProcess.csを修正して、info.plistファイルやSigning & CapabilitiesからHive SDK機能を自動的に追加または削除することは、現在のHive SDKバージョンでのみ可能です。HivePostProcess.csが修正されている状態でHive SDKバージョンをHive SDK Managerで更新すると、競合が発生する可能性があります。この機能をHive SDKバージョンに関係なく使用するには、HivePostProcess.csを修正せず、代わりにPBX Project APIに基づいて別のポストプロセッシングスクリプト(例:GamePostProcess.cs)を実装してください。
Xcode info.plist ファイルに詳細設定を追加する¶
選択した機能を使用するために必要な詳細設定をHive > ExternalDependencyから追加してください。UnityでXcodeプロジェクトをビルドする前に、HivePostProcess.csファイル内のコードのコメントを外すことで、Hive SDKを使用するための詳細設定がinfo.plistファイルに自動的に追加されます。コードのコメントを外すと、設定が削除されます。
以下のコードで特定の行をコメントアウトすると、対応する設定がinfo.plistファイルに追加されるのを防ぐことができます。
private static void iOSSettingInfoPlist(string buildPath) {
   #if UNITY_IOS
    var PlistPath = buildPath + "/Info.plist";
   PlistDocument plist = new PlistDocument();
   plist.ReadFromFile(PlistPath);
    var rootDict = plist.root;
   rootDict.SetBoolean("UIViewControllerBasedStatusBarAppearance",false);
   if( hasFacebookAppId() )
       rootDict.SetString("FacebookAppID",getFacebookAppID());
   if (hasFacebookClientToken())
       rootDict.SetString("FacebookClientToken", getFacebookClientToken());
    rootDict.SetString("CFBundleIdentifier",getBundleIdentifier());
    //facebook white list
   var LSApplicationQueriesSchemes = rootDict.CreateArray("LSApplicationQueriesSchemes");
   LSApplicationQueriesSchemes.AddString("fbapi");
   LSApplicationQueriesSchemes.AddString("fb-messenger-share-api");
    // for vk
   LSApplicationQueriesSchemes.AddString("vk");
   LSApplicationQueriesSchemes.AddString("vkauthorize");
   LSApplicationQueriesSchemes.AddString("vk-share");
    // for WeChat
   LSApplicationQueriesSchemes.AddString("weixin");
   LSApplicationQueriesSchemes.AddString("weixinULAPI");
    // for QQ
   LSApplicationQueriesSchemes.AddString("mqqOpensdkSSoLogin");
   LSApplicationQueriesSchemes.AddString("mqqopensdkapiV2");
   LSApplicationQueriesSchemes.AddString("mqqopensdkapiV3");
   LSApplicationQueriesSchemes.AddString("wtloginmqq2");
   LSApplicationQueriesSchemes.AddString("mqq");
   LSApplicationQueriesSchemes.AddString("mqqapi");
   LSApplicationQueriesSchemes.AddString("mqqopensdknopasteboard");
   LSApplicationQueriesSchemes.AddString("mqqopensdknopasteboardios16");
   LSApplicationQueriesSchemes.AddString("lineauth2");
    //URL Types settings
   var CFBundleURLTypes = rootDict.CreateArray("CFBundleURLTypes");
    var facebookURLType = CFBundleURLTypes.AddDict();
   facebookURLType.SetString("CFBundleTypeRole","Editor");
   if( hasFacebookAppId() )
       facebookURLType.CreateArray("CFBundleURLSchemes").AddString("fb"+getFacebookAppID());
    // add Google reversed client id
   if (hasGoogleReversedClientId()){
       var googleReversedClientId = CFBundleURLTypes.AddDict();
       googleReversedClientId.SetString("CFBundleTypeRole","Editor");
       googleReversedClientId.CreateArray("CFBundleURLSchemes").AddString(getGoogleReversedClientId());
   }
   // add tencent appid
   if (hasQQAppId()){
       var qqAppId = CFBundleURLTypes.AddDict();
       qqAppId.SetString("CFBundleTypeRole","Editor");
       qqAppId.CreateArray("CFBundleURLSchemes").AddString("tencent"+getQQAppId());
   }
   // add VK appid
   if (hasVKAppId()) {
       var vkAppId = CFBundleURLTypes.AddDict();
       vkAppId.SetString("CFBundleTypeRole","Editor");
       vkAppId.CreateArray("CFBundleURLSchemes").AddString("vk"+getVKAppId());
   }
    // add wechat appid
   if (hasWeChatAppId()) {
       var weChatAppId = CFBundleURLTypes.AddDict();
       weChatAppId.SetString("CFBundleTypeRole","Editor");
       weChatAppId.CreateArray("CFBundleURLSchemes").AddString(getWeChatAppId());
   }
    // add line channel id
   if (hasLineChannelId()) {
       var lineChannelId = CFBundleURLTypes.AddDict();
       lineChannelId.SetString("CFBundleTypeRole","Editor");
       lineChannelId.CreateArray("CFBundleURLSchemes").AddString("line3rdp."+getBundleIdentifier());
   }
    var urlSchemes = CFBundleURLTypes.AddDict();
   urlSchemes.SetString("CFBundleTypeRole","Editor");
   urlSchemes.SetString("CFBundleIdentifier",getBundleIdentifier());
   urlSchemes.CreateArray("CFBundleURLSchemes").AddString(getBundleIdentifier());
    // remove exit on suspend if it exists.
   string exitsOnSuspendKey = "UIApplicationExitsOnSuspend";
   if(rootDict.values.ContainsKey(exitsOnSuspendKey))
   {
       rootDict.values.Remove(exitsOnSuspendKey);
   }
    // Set encryption usage boolean
   string encryptKey = "ITSAppUsesNonExemptEncryption";
   rootDict.SetBoolean(encryptKey, false);
    // ATS
   var ATSDict = rootDict.CreateDict("NSAppTransportSecurity");
   ATSDict.SetBoolean("NSAllowsArbitraryLoads",true);
    plist.WriteToFile(PlistPath);
    #endif
}
Warning
HivePostProcess.csを修正して、info.plistファイルやSigning & CapabilitiesからHive SDK機能を自動的に追加または削除することは、現在のHive SDKバージョンでのみ可能です。HivePostProcess.csが修正されている状態でHive SDKバージョンをHive SDK Managerで更新すると、競合が発生する可能性があります。この機能をHive SDKバージョンに関係なく使用するには、HivePostProcess.csを修正せず、代わりにPBX Project APIに基づいた別のポストプロセッシングスクリプト(例:GamePostProcess.cs)を実装してください。
HivePostProcess.csは特定のファイルをリンクするためにも使用できます。例えば、Hive SDK分析を使用する際に、Unity > Hive DependenciesでFirebaseを有効にすることができます。次に、Google Firebase ConsoleからダウンロードしたGoogleService-Info.plistファイルをAssets/ExternalResources/iOSディレクトリに配置した後、以下のコードをHivePostProcess.csに追加します。これにより、Unityを使用して構築されたXcodeプロジェクトにGoogleService-Info.plistファイルが自動的にリンクされます。
private static void iOSSettingProject(string buildPath) {
   ...
   // If you want to disable the feature of automatically adding GoogleService-Info.plist file to the Xcode project, comment out the line below.
   iOSAddGoogleServiceInfoPlist(buildPath, project, targets[mainTarget]);
   ...
}
#if UNITY_IOS
public static void iOSAddGoogleServiceInfoPlist(string buildPath, PBXProject project, string target) {
   var isUseFirebase = ExternalDependencyDictionaryManager.isUseDependency(ExternalDependencyType.Firebase);
   if (!isUseFirebase) {
       Debug.Log("[iOSAddGoogleServiceInfoPlist] ExternalDependencyType Firebase not use. Skip process.");
       return;
   }
   string[] filesToCopy = new string[]
   {
       "GoogleService-Info.plist",
   };
   foreach (string file in filesToCopy) {
       var srcPath = Path.Combine("Assets/ExternalResources/iOS", file);
       var relativePath = Path.Combine("", file);
       var physicalPath = Path.Combine(buildPath, relativePath);
       if (!File.Exists(srcPath)) {
           Debug.Log("[iOSAddGoogleServiceInfoPlist] " + file + " not exist. Skip process.");
           continue;
       }
       Debug.Log("[iOSAddGoogleServiceInfoPlist] srcPath = " + srcPath);
       Debug.Log("[iOSAddGoogleServiceInfoPlist] relativePath = " + relativePath);
       Debug.Log("[iOSAddGoogleServiceInfoPlist] physicalPath = " + physicalPath);
       File.Copy(srcPath, physicalPath, true);
       var fileGuid = project.AddFile(physicalPath, relativePath);
       Debug.Log("[iOSAddGoogleServiceInfoPlist] fileGuid = " + fileGuid);
       project.AddFileToBuild(target, fileGuid);
   }
} 
#endif
使用されていないXMLファイルの削除¶
Hive SDK UnityをUnityパッケージ経由でインストールまたは更新した場合は、Hive SDK Managerではなく、アプリをビルドする前に以下のパスにあるすべてのHIVESDK_{library_name}Dependencies.xmlファイルを削除する必要があります。
- Assets/Hive_SDK_v4/Dependencies
- Assets/Hive_SDK_v4/Editor
削除されるファイルの例は次のとおりです:
- HIVESDK_DefaultDependencies.xml
- HIVESDK_HerculesDependencies.xml
- HIVESDK_HiveAnalyticsConsentModeDependencies.xml
- HIVESDK_HiveDataStoreDependencies.xml
- HIVESDK_HiveDeviceManagementDependencies.xml
- HIVESDK_HiveGoogleInAppReviewDependencies.xml
- HIVESDK_HiveGoogleInAppUpdateDependencies.xml
- HIVESDK_HivePromotionDependencies.xml
- HIVESDK_HiveRealNameVerificationDependencies.xml
- HIVESDK_MarketAmazonDependencies.xml
- HIVESDK_MarketAppleDependencies.xml
- HIVESDK_MarketGoogleDependencies.xml
- HIVESDK_MarketHiveStoreDependencies.xml
- HIVESDK_MarketHuaweiDependencies.xml
- HIVESDK_MarketLebiDependencies.xml
- HIVESDK_MarketOneStoreDependencies.xml
- HIVESDK_MarketSamsungDependencies.xml
- HIVESDK_ProviderAdjustDependencies.xml
- HIVESDK_ProviderAppleDependencies.xml
- HIVESDK_ProviderAppleSignInDependencies.xml
- HIVESDK_ProviderAppsFlyerDependencies.xml
- HIVESDK_ProviderFacebookDependencies.xml
- HIVESDK_ProviderFirebaseDependencies.xml
- HIVESDK_ProviderGoogleDependencies.xml
- HIVESDK_ProviderGooglePlayGamesDependencies.xml
- HIVESDK_ProviderHiveMembershipDependencies.xml
- HIVESDK_ProviderHuaweiDependencies.xml
- HIVESDK_ProviderLineDependencies.xml
- HIVESDK_ProviderQQDependencies.xml
- HIVESDK_ProviderRecaptchaDependencies.xml
- HIVESDK_ProviderSingularDependencies.xml
- HIVESDK_ProviderVKDependencies.xml
- HIVESDK_ProviderWechatDependencies.xml
- HIVESDK_ProviderWeverseDependencies.xml
- HIVESDK_PushAmazonAdmDependencies.xml
- HIVESDK_PushGoogleFcmDependencies.xml

