question

FENG LI avatar image
FENG LI asked

PlayFabDataAPI.InitiateFileUploads callbacks not working while inBackground?

I'm using the newest version of SDK in Unity, build for both Android and iOS.

I want to upload the game progress file in a frequency, and specially, when user minimize the app i will force to do a uploading:

void OnApplicationPause(bool paused){
    if(paused){
        ... create request 
        PlayFabDataAPI.InitiateFileUploads(request, OnInitFileUpload, OnInitFailed);
        Debug.Log("start upload.");
    }
}

void OnInitFileUpload(InitiateFileUploadsResponse response){
    Debug.Log("upload inited.");
}
void OnInitFailed(PlayFabError error){
    Debug.Log(error);
}


We will get "start upload" log after minimizing, but "upload inited" will not be triggered while in background ever, when i restore the app to foreground, then the "upload inited" fired.

So, it indicated that we can not finish InitiateFileUploads in background mode to do a uploading. Both Android iOS tested, same.

I am wondering, is there a way to achieve this? Or no way, we just can not do uploading in background?

Thanks in advance!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JayZuo avatar image
JayZuo answered

This actually is a Unity question. Android and iOS will suspend your application while it's in background. So you can't do a lot of things in OnApplicationPause.

I found two related question in Unity Forums: https://forum.unity.com/threads/unitywebrequest-how-to-continue-the-web-request-even-when-app-in-pause.464250/ and https://forum.unity.com/threads/onapplicationpause-and-save-data-to-file.532012/ which might help you. I'm not familiar with this, I'd suggest you seek for help in Unity Forums.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

FENG LI avatar image FENG LI commented ·

Thanks for the answer, but the links does not helps.

Well, from the logcat, i saw there's many thread of my game are active, for example the IAP, if it is not get the info it will retry even in background, also the advertising plugins.

So i guess there must be a way.

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ FENG LI commented ·

PlayFab Unity SDK is just a wapper of PlayFab's RESTful API to help you send requests and handle received responses. In Unity, by default, it will use UnityWebRequest under the hood. As in the first question, UnityWebRequest will also pause when app is paused. I'm not a Unity expert, not sure how to solve this issue, that's why I suggest you seek help in Unity Forums.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.