How to add Cloud Documnts capatimitlty?

Hello there!

I need to add support of GKSavedGame.
For that purpose i need to add iCloud Documents to the entitlements list.
I see that engine can’t do it byself.

I added icloud documents capatibility and data container to my provision.

Firstly i wrote test ios applcation on pure objective-c under xcode.
I tested all features i need:

  1. Save data to cloud
  2. Load saved data
  3. Resolve conflicts

All works fine.

Then i started to work with unreal engine.
When i enable cloud kit support - it appears in .entitlements file. But i need iCloud Documents to work with GKSavedGame.

So i modified binary engine version - Engine/Source/Programs/UnrealBuildTool/IOS/UEDeployIOS.cs
I added missing entitlements.
To recompile UnrealBuildTool in a binary version of the engine we just need to regenerate xcode project.


private void WriteEntitlementsFile(string OutputFilename, FileReference ProjectFile)
    {
    	// get the settings from the ini file
    	// plist replacements
    	// @todo tvos: Separate TVOS version?
    	ConfigCacheIni Ini = ConfigCacheIni.CreateConfigCacheIni(UnrealTargetPlatform.IOS, "Engine", DirectoryReference.FromFile(ProjectFile));
    	bool bSupported = false;
    	Ini.GetBool("/Script/IOSRuntimeSettings.IOSRuntimeSettings", "bEnableCloudKitSupport", out bSupported);
    
            Directory.CreateDirectory(Path.GetDirectoryName(OutputFilename));
    	// we need to have something so Xcode will compile, so we just set the get-task-allow, since we know the value, 
    	// which is based on distribution or not (true means debuggable)
    	StringBuilder Text = new StringBuilder();
    	Text.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    	Text.AppendLine("<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
    	Text.AppendLine("<plist version=\"1.0\">");
    	Text.AppendLine("<dict>");
    	Text.AppendLine(string.Format("	<key>get-task-allow</key><{0}/>",	/*Config.bForDistribution ? "false" : */"true"));
    	if (bSupported)
    	{
				Text.AppendLine("	<key>com.apple.developer.icloud-container-identifiers</key>");
				Text.AppendLine("	<array>");
				Text.AppendLine("		<string>iCloud.$(CFBundleIdentifier)</string>");
				Text.AppendLine("	</array>");
				Text.AppendLine("	<key>com.apple.developer.icloud-services</key>");
				Text.AppendLine("	<array>");
				Text.AppendLine("		<string>CloudKit</string>");
**				Text.AppendLine("		<string>CloudDocuments</string>");**
				Text.AppendLine("	</array>");
**				Text.AppendLine("	<key>com.apple.developer.ubiquity-container-identifiers</key>");**
				Text.AppendLine("	<array>");
**				Text.AppendLine("		<string>iCloud.$(CFBundleIdentifier)</string>");**
				Text.AppendLine("	</array>");
    	}
    	Text.AppendLine("</dict>");
    	Text.AppendLine("</plist>");
    	File.WriteAllText(OutputFilename, Text.ToString());
    }

For now i see that my application appeared in iCloud permissions settings.
It try to send data to iCloud but gets error:
GKErrorDomain 27. It means that application have no rights to work with iCloud Drive.

I took a look on build log and found that app.xcent was generated without iCloud Documents entitlement.
I took same file from my test xcode project and used it to sign my game. And now application have rights on runtime (but have another error 17 - wring data format or something like that - i will solve it later).

What should i do to generate app.xcent file correctly on engine side to get all entitlements for iCloud Documents and with appropriate icloud container.

Thanks!

xcent file should looks like that


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>application-identifier</key>
	<string>ID.com.company.game</string>
	<key>com.apple.developer.team-identifier</key>
	<string>ID</string>
	<key>get-task-allow</key>
	<true/>
	<key>aps-environment</key>
	<string>development</string>
	<key>com.apple.developer.icloud-container-identifiers</key>
	<array>
		<string>iCloud.com.company.game</string>
	</array>
	<key>com.apple.developer.icloud-services</key>
	<array>
		<string>CloudKit</string>
		<string>CloudDocuments</string>
	</array>
	<key>com.apple.developer.ubiquity-container-identifiers</key>
	<array>
		<string>iCloud.com.company.game</string>
	</array>
</dict>
</plist>


If i replace xcent file content by that - icloud documents works fine!

but looks like that:



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>application-identifier</key>
	<string>ID.com.company.game</string>
	<key>com.apple.developer.team-identifier</key>
	<string>ID</string>
	<key>get-task-allow</key>
	<true/>
	<key>keychain-access-groups</key>
	<array>
		<string>ID.com.company.game</string>
	</array>
</dict>
</plist>


hi there! I’m working on a blueprint project, i’m new to CloudKit, i’m wondering is it possible to upload save file to iCloud and later on retrieve from it?

It is possible… but you should to implement all iOS functionality by self.

If we talking about saves - you need to research GKSavedGame API for iOS.

Next - you need to implement some handlers.

But the most difficult - is to add support of that feature to the engine.

Read out my prev messages to determine how it works.

Hi! As i’m working on Blueprint Only project i’m wondering whether i should add your above code to the project plist? Sorry, i’m bad in programming… do you mind roughly elaborate how can i approach it? Really much appreciate it!

Nope. You should to change UnrealBuildTool code to change entitlements.
Then you need to create xcent file with permissions to CloudDocuments.
Also you need to add CloudDocuments and Container to mobile provision.

1.Launch the Settings app on your iPhone or iPad.
2.Tap on iCloud.
3.Tap on Documents & Data.
4.Turn On the option for Documents & Data at the top.
5.You can also specify underneath that which apps you’d like to be able to store documents and data in the cloud. Turn Off the ones you don’t want to grant permission.