Unity iOS
This guides the Hive SDK Unity iOS app building and configuration.
Add permissions to Xcode Signing & Capabilities¶
Add permissions to your Xcode project to use the features you selected from Hive > ExternalDependency. You can add them using the Hive PostProcess editor or HivePostProcess.cs.
Adding through the Hive postprocess editor¶
Run the Hive PostProcess editor from your Unity development environment by going to Hive > Build project post process settings > iOS or Hive > Edit Config > Build iOS project post process settings. Then, you can select the desired Hive SDK features and add permissions to the Xcode Signing & Capabilities section.
Here are the Hive SDK features that can be added:
- Push Notifications: Activates local and remote push features.
- Development Mode: Set when using a development provisioning profile certificate.
- Release Mode: Set when using a release provisioning profile certificate.
- Background Mode (Remote Notifications): Determines whether to receive remote push notifications when the app is in the background.
- Apple Sign In: Activates Sign In with Apple login functionality.
- Associated Domains: List of domains allowed for Universal Links (allowing installation and execution of the app from a website).
- In-App Purchase: Activates in-app purchase functionality.
- Game Center: Activates Game Center login and related functions.
Click Apply to add the selected features to Xcode Signing & Capabilities. Click Reset to reset the settings to their default values.
The configured values are saved as a JSON string in Assets > Hive_SDK_v4 > PostProcess > iOS > HivePostProcessSettingIOS.txt.
Note
You can also modify the Xcode project capabilities by directly editing the content of the HivePostProcessSettingiOS.txt file without using the Hive PostProcess Editor.
Adding through HivePostProcess.cs¶
Before building the Xcode project in Unity, uncommenting the code in the HivePostProcess.cs file will automatically add the Hive SDK feature permissions to Xcode Signing & Capabilities. Commenting out the code will remove the permissions.
Commenting out specific lines in the code below will prevent the corresponding permissions from being added to Signing & Capabilities. It is recommended to comment out code for permissions you do not intend to use.
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
Modifying HivePostProcess.cs to automatically add or remove Hive SDK features from info.plist files and Signing & Capabilities is only possible with the current Hive SDK version. Updating the Hive SDK version with the Hive SDK Manager while HivePostProcess.cs is modified can lead to conflicts. To use this functionality regardless of the Hive SDK version, avoid modifying HivePostProcess.cs and instead implement a separate post-processing script (e.g., GamePostProcess.cs) based on the PBX Project API.
Adding detailed settings to Xcode info.plist file¶
Add detailed settings required for using the features selected from Hive > ExternalDependency. Before building the Xcode project in Unity, uncommenting the code in the HivePostProcess.cs file will automatically add the detailed settings for using Hive SDK to the info.plist file. Commenting out the code will remove the settings.
Commenting out specific lines in the code below will prevent the corresponding settings from being added to the info.plist file.
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
Modifying HivePostProcess.cs to automatically add or remove Hive SDK features from info.plist files and Signing & Capabilities is only possible with the current Hive SDK version. Updating the Hive SDK version with the Hive SDK Manager while HivePostProcess.cs is modified can lead to conflicts. To use this functionality regardless of the Hive SDK version, avoid modifying HivePostProcess.cs and instead implement a separate post-processing script (e.g., GamePostProcess.cs) based on the PBX Project API.
HivePostProcess.cs can also be used to link specific files. For example, when using Hive SDK analytics, you can enable Firebase in Unity > Hive Dependencies. Then, after placing the GoogleService-Info.plist file downloaded from the Google Firebase Console in the Assets/ExternalResources/iOS directory, add the following code to HivePostProcess.cs. This will automatically link the GoogleService-Info.plist file to the Xcode project built using Unity.
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
Deleting unused XML files¶
If you installed or updated the Hive SDK Unity via the Unity package instead of the Hive SDK Manager, you must delete all HIVESDK_{library_name}Dependencies.xml files located in the paths below before building the app.
- Assets/Hive_SDK_v4/Dependencies
- Assets/Hive_SDK_v4/Editor
The examples of files to be deleted are as follows:
- 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