You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
UE-52763 tvOS/iOS: Allow save games to save to iCloud
UE-52346 TM-Gameplay: Load Level Volume Fails to Read TestSlot.sav file
UE-64066 TM-Gameplay Load Game does not work on TVOS
#jira UE-52763
#jira UE-52346
#jira UE-64066
#iOS
#4.22
#rb Jack.Porter
Adapted the Online iCloud plugin to work without enabling the Game Center plugin (using empty UniqueNetId as a parameter for FOnlineUserCloudInterfaceIOS methods and callbacks)
At plugin init, the data from the iCloud will overwrite the local storage.
Replaced saveRecord with CKModifyRecordsOperation to avoid errors on existing iCloud records - using savePolicy = CKRecordSaveAllKeys to overwrite the previously uploaded save file
Entitlements:
Fixed the problem with writing the iCloud lines in UE4Game.entitlements : The flag from DefaultEngine.ini was overwritten by IOSEngine.ini (same section & key). Same issue with the Game Center flag
Signing:
It looks like there is a problem (since Xcode 6/iOS8, when Apple has changed the format for the iCloud entitlements, in order to support CloudKit) with the Entitlements section from the provisioning file (downloaded from Apple Developper) <key>com.apple.developer.icloud-services</key> contains "*" instead of the CloudKit and CloudDocuments entries. Fixed it, otherwise the app won't appear in the iPhone's Settings->iCloud apps menu
[CL 4760235 by Sorin Gradinaru in Dev-Mobile branch]
80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "IOSSaveGameSystem.h"
|
|
#include "GameDelegates.h"
|
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogIOSSaveGame, Log, All);
|
|
|
|
//
|
|
// Implementation members
|
|
//
|
|
|
|
FIOSSaveGameSystem::FIOSSaveGameSystem()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
FIOSSaveGameSystem::~FIOSSaveGameSystem()
|
|
{
|
|
Shutdown();
|
|
}
|
|
|
|
void FIOSSaveGameSystem::Initialize()
|
|
{
|
|
}
|
|
|
|
void FIOSSaveGameSystem::Shutdown()
|
|
{
|
|
}
|
|
|
|
ISaveGameSystem::ESaveExistsResult FIOSSaveGameSystem::DoesSaveGameExistWithResult(const TCHAR* Name, const int32 UserIndex)
|
|
{
|
|
if (IFileManager::Get().FileSize(*GetSaveGamePath(Name)) >= 0)
|
|
{
|
|
return ESaveExistsResult::OK;
|
|
}
|
|
return ESaveExistsResult::DoesNotExist;
|
|
}
|
|
|
|
bool FIOSSaveGameSystem::SaveGameNoCloud(const TCHAR* Name, const TArray<uint8>& Data)
|
|
{
|
|
return FFileHelper::SaveArrayToFile(Data, *GetSaveGamePath(Name));
|
|
}
|
|
|
|
bool FIOSSaveGameSystem::SaveGame(bool bAttemptToUseUI, const TCHAR* Name, const int32 UserIndex, const TArray<uint8>& Data)
|
|
{
|
|
// send to the iCloud, if enabled
|
|
OnWriteUserCloudFileBeginDelegate.ExecuteIfBound(FString(Name), Data);
|
|
|
|
return FFileHelper::SaveArrayToFile(Data, *GetSaveGamePath(Name));
|
|
}
|
|
|
|
bool FIOSSaveGameSystem::LoadGame(bool bAttemptToUseUI, const TCHAR* Name, const int32 UserIndex, TArray<uint8>& Data)
|
|
{
|
|
// try to read it from the iCloud, if enabled
|
|
OnReadUserCloudFileBeginDelegate.ExecuteIfBound(FString(Name), Data);
|
|
|
|
if (Data.Num() > 0)
|
|
{
|
|
// we've received data from the iCloud, the save file was overwritten
|
|
return true;
|
|
}
|
|
|
|
// no iCloud data, read from the local storage
|
|
return FFileHelper::LoadFileToArray(Data, *GetSaveGamePath(Name));
|
|
}
|
|
|
|
bool FIOSSaveGameSystem::DeleteGame(bool bAttemptToUseUI, const TCHAR* Name, const int32 UserIndex)
|
|
{
|
|
// delete the file from the iCloud
|
|
OnDeleteUserCloudFileBeginDelegate.ExecuteIfBound(FString(Name));
|
|
|
|
// delete the file from the local storage
|
|
return IFileManager::Get().Delete(*GetSaveGamePath(Name), true, false, !bAttemptToUseUI);
|
|
}
|
|
|
|
FString FIOSSaveGameSystem::GetSaveGamePath(const TCHAR* Name)
|
|
{
|
|
return FString::Printf(TEXT("%s""SaveGames/%s.sav"), *FPaths::ProjectSavedDir(), Name);
|
|
}
|