Unreal Engine 4
This guide explains the tasks to perform after installing Hive SDK.
Setting the auto-rotate screen feature¶
The following settings are required when the screen orientation is set to both landscape and portrait.
Android¶
For Android app builds, if you set the screen orientation to both landscape and portrait, the following code change is required for the auto-rotate screen feature to work properly.
- Go to /Engine/Build/Android/Java/src/com/epicgames/ue4/GameActivity.java.template.
- Add the
HiveActivity.onConfigurationChanged()API.@Override public void onConfigurationChanged(Configuration newConfig) { HiveActivity.onConfigurationChanged(this, newConfig); // Add super.onConfigurationChanged(newConfig); // forward the orientation boolean bPortrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT; nativeOnConfigurationChanged(bPortrait); }
iOS¶
For bidirectional screen rotation to work properly on iOS, implement the screen rotation-related method application(\_:supportedInterfaceOrientationsFor:) in Unreal Engine's IOSAppDelegate.cpp file. This method returns the UIInterfaceOrientationMask value to apply to the game. A landscape-only game returns landscape, a portrait-only game returns portrait, and a game that supports both landscape and portrait returns both landscape and portrait.
Add the following code to /Engine/Source/Runtime/ApplicationCore/Private/IOS/IOSAppDelegate.cpp.
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// TODO: Landscape-only game
return UIInterfaceOrientationMaskLandscape;
// TODO: Portrait-only game
return UIInterfaceOrientationMaskPortrait;
// TODO: Game that supports both landscape and portrait
return UIInterfaceOrientationMaskAll;
}
Setting Swift compatibility (iOS)¶
In an iOS development environment, add the lines or blocks marked with 'Add' comments in the following files for compatibility between Unreal Engine 4 and the Swift language.
Engine/Source/Programs/UnrealBuildTool/ProjectFiles/Xcode/XcodeProject.cs
{
Content.Append("\t\t\t\t\"PRODUCT_BUNDLE_IDENTIFIER[sdk=iphoneos*]\" = " + IOS_BUNDLE + ";" + ProjectFileGenerator.NewLine);
}
// Add
if (ProjectFile != null)
{
Content.Append("\t\t\t\tSWIFT_VERSION = 5.0;" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tSWIFT_OBJC_BRIDGING_HEADER = \"" + GamePath + "/dummy-Bridging-Header.h\";" + ProjectFileGenerator.NewLine);
}
// Add End
}
if (TVOSRunTimeVersion != null)
{
if (XcodeProjectFileGenerator.bGeneratingRunIOSProject)
{
Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;"+ ProjectFileGenerator.NewLine); // Add
Content.Append("\t\t\t\tINFOPLIST_FILE = \"" + IOSInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tCODE_SIGN_ENTITLEMENTS = \"" + IOSEntitlementPath + "\";" + ProjectFileGenerator.NewLine);
}
Content.Append("\t\t\t\t\"INFOPLIST_FILE[sdk=macosx*]\" = \"" + MacInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
if (IOSRunTimeVersion != null)
{
Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;"+ ProjectFileGenerator.NewLine); // Add
Content.Append("\t\t\t\t\"INFOPLIST_FILE[sdk=iphoneos*]\" = \"" + IOSInfoPlistPath + "\";" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\t\"CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]\" = \"" + IOSEntitlementPath + "\";" + ProjectFileGenerator.NewLine);
}
Engine/Source/Programs/UnrealBuildTool/Platform/IOS/IOSToolChain.cs
Result += " -Xlinker \\\"" + Path.GetDirectoryName(OutputFile.AbsolutePath) + "\\\"";
}
Result += " -Xlinker -rpath -Xlinker /usr/lib/swift"; // Add
Result += " -dead_strip";
Result += " -m" + GetXcodeMinVersionParam() + "=" + ProjectSettings.RuntimeVersion;
Result += " -Wl";
Setting entitlements (iOS)¶
Unreal Engine dynamically creates the entitlements file for signing through UnrealBuildTool at build time. Add the required entitlement entries as follows.
- Add through project settings: Some common entitlement entries can be enabled directly in the Project Settings menu of the Unreal Editor.
- Add by modifying engine source: Other entries that are not supported in project settings must be added by directly modifying the entitlement generation code in the UnrealBuildTool engine source file below.
- File to modify: Engine/Source/Programs/UnrealBuildTool/Platform/IOS/IOSExport.cs
The entitlement entries required for each Hive SDK feature and how to add them are as follows. Add only the entries for the features used by your app, which must also be enabled as capabilities in the provisioning profile. For details about each entry, see the official Apple documentation.
| Feature used | Required entitlement | How to add |
|---|---|---|
| Remote push | aps-environment | Check Enable Remote Notifications Support under Online in Project Settings > Platforms > iOS |
| Sign in with Apple (IdP) | com.apple.developer.applesignin | Add bEnableSignInWithAppleSupport=True to the [/Script/IOSRuntimeSettings.IOSRuntimeSettings] section in Config/DefaultEngine.ini |
| Universal links (deep links/invitation links) | com.apple.developer.associated-domains | Modify IOSExport.cs. For domain configuration, see Setting up universal links |
| Game Center login (IdP) | com.apple.developer.game-center | Modify IOSExport.cs |
| Age declaration (AgeRange module) | com.apple.developer.declared-age-range | Modify IOSExport.cs. For details, see App Store compliance |
When modifying IOSExport.cs, add the required entries between 'Add' and 'Add End' at the location below.
Text.AppendLine( "<dict>");
Text.AppendLine( "\t<key>get-task-allow</key>");
Text.AppendLine(string.Format( "\t<{0}/>", bForDistribution ? "false": "true"));
// Add - Add the required entitlement entries. The following is a Game Center example.
Text.AppendLine("\t<key>com.apple.developer.game-center</key>");
Text.AppendLine("\t<true/>");
// Add End
if (bCloudKitSupported) {
if (iCloudContainerIdentifiersXML != "")
Note
Modifying the IOSExport.cs file is a source code change to UnrealBuildTool (UBT). You do not need to rebuild the entire engine. UBT is automatically compiled during the next project build, and the change is applied immediately.
After building, verify that the entitlements are applied to the app as follows.
Applying HIVEAppDelegate (iOS)¶
Starting with Hive SDK v4 26.4.1, HIVEAppDelegate swizzling is performed automatically inside the Hive SDK plugin. The plugin handles this automatically when the app launches, so no additional work is required in the app code.
Removing existing integration code for versions earlier than v4 26.4.1
If you are using a version earlier than Hive SDK v4 26.4.1, remove the previous modifications when updating.
-
Remove manual HIVEAppDelegate invocation code: Referring to the "Applying HIVEAppDelegate (iOS)" step in the previous guide, remove the following type of code block added during app initialization from the project.
#if PLATFORM_IOS UIApplication * dummyApplication = [UIApplication sharedApplication]; Class clzHIVEAppDelegate = NSClassFromString(@"HIVEAppDelegate"); SEL selApplicationDidFinishLaunchingWithOptions = NSSelectorFromString(@"application:didFinishLaunchingWithOptions:"); if( clzHIVEAppDelegate != nil && [clzHIVEAppDelegate respondsToSelector:selApplicationDidFinishLaunchingWithOptions] ) { NSMethodSignature *method = [clzHIVEAppDelegate methodSignatureForSelector:selApplicationDidFinishLaunchingWithOptions]; if (method != nil) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:method]; [invocation setSelector:selApplicationDidFinishLaunchingWithOptions]; [invocation setTarget:clzHIVEAppDelegate]; [invocation setArgument:(void*)&dummyApplication atIndex:2]; NSDictionary *localLaunchOptions = [IOSAppDelegate GetDelegate].launchOptions; if( localLaunchOptions != nil ) { [invocation setArgument:(void*)&localLaunchOptions atIndex:3]; } [invocation invoke]; } } #endif -
Remove deep link delegate subscription code: Referring to the "Adding promotion code for deep link setup (iOS)" step in the previous guide, remove the following type of subscription and handler code added to
GameInstanceor similar classes.-
The logic inside the handler may be implemented as
Promotion::processURI(...)orFHivePromotion::ProcessURI(...), depending on the interface you use.// Subscription code (GameInstance::Init, etc.) - remove FIOSCoreDelegates::OnOpenURLwithOptions.AddUObject(this, &UMyGameInstance::ApplicationOpenURL); // Handler - remove (including the declaration in the header) void UMyGameInstance::ApplicationOpenURL(UIApplication* application, NSURL* url, NSDictionary* options) { Promotion::processURI(std::string([[url absoluteString] UTF8String])); }
-
-
Remove Blueprint bootstrap trigger calls: Remove all custom trigger functions defined in your app and called from Blueprint, such as
RemoveOpenURLDelegate(), as well as the corresponding call nodes.If the in-app delegate subscription described above has been removed correctly, existing openURL-related code changes applied directly to a custom engine (
IOSAppDelegate.h,IOSAppDelegate.cpp) do not affect engine behavior. Therefore, you can leave that code as is without removing or rolling it back.