Files
UnrealEngineUWP/Engine/Source/Runtime/Online/BackgroundHTTP/Private/BackgroundHttpNotificationObject.cpp
thomas ross ba30c91d75 Adding background http protype system. Enables downloading files while app is suspended on iOS. Other platforms need to be added over time if desired. For now other platforms just wrap basic HTTPRequests under the hood.
#rb none
#tests iOS / Android
[CODEREVIEW] Andrew.Grant,Daniel.Lamb,Justin.Marcus
[FYI] Pete.Sauerbrei


#ROBOMERGE-SOURCE: CL 4898958 via CL 4898963 via CL 4898965 via CL 4905881

[CL 4906509 by thomas ross in Main branch]
2019-02-05 18:09:08 -05:00

56 lines
1.8 KiB
C++

// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
#include "BackgroundHttpNotificationObject.h"
#include "LocalNotification.h"
FBackgroundHttpNotificationObject::FBackgroundHttpNotificationObject(FText InNotificationTitle, FText InNotificationBody, FText InNotificationAction, const FString& InNotificationActivationString, bool InNotifyOnlyOnFullSuccess)
: NotificationTitle(InNotificationTitle)
, NotificationAction(InNotificationAction)
, NotificationBody(InNotificationBody)
, NotificationActivationString(InNotificationActivationString)
, bNotifyOnlyOnFullSuccess(InNotifyOnlyOnFullSuccess)
, NumFailedDownloads(0)
, PlatformNotificationService(nullptr)
{
if (GConfig)
{
FString ModuleName;
GConfig->GetString(TEXT("LocalNotification"), TEXT("DefaultPlatformService"), ModuleName, GEngineIni);
if (ModuleName.Len() > 0)
{
// load the module by name from the .ini
if (ILocalNotificationModule* Module = FModuleManager::LoadModulePtr<ILocalNotificationModule>(*ModuleName))
{
PlatformNotificationService = Module->GetLocalNotificationService();
}
}
}
}
FBackgroundHttpNotificationObject::~FBackgroundHttpNotificationObject()
{
if (nullptr != PlatformNotificationService)
{
if (!bNotifyOnlyOnFullSuccess || (NumFailedDownloads == 0))
{
//make a notification 1 second from now
FDateTime TargetTime = FDateTime::Now();
TargetTime += FTimespan::FromSeconds(1);
if (nullptr != PlatformNotificationService)
{
PlatformNotificationService->ScheduleLocalNotificationAtTime(TargetTime, true, NotificationTitle, NotificationBody, NotificationAction, NotificationActivationString);
}
}
}
}
void FBackgroundHttpNotificationObject::NotifyOfDownloadResult(bool bWasSuccess)
{
if (!bWasSuccess)
{
FPlatformAtomics::InterlockedIncrement(&NumFailedDownloads);
}
}