iOs and asset bundles?

Hello,

We recently created an app that downloads an assetbundle on firsh launch and stores it in Application.persistentDataPath. Apple rejected it because that data is backed up on iCloud.

This is the link they sent: Optimizing Your App’s Data for iCloud Backup | Apple Developer Documentation

In that link, it specifies that data that is required for offline play must be marked “do not backup”. I don’t recall ever seeing this option in Unity, so is there a manual way to do so in Unity?

This would be a problem for anyone using assetbundles as a one time storage and not storing them in the cache.

Before suggesting this, we’ve tried storing the asset bundle in the cache. However, it swelled to 100mb +. Storing it out side the cache let it remain the initial 2.7mb. I’ve also seen some discussion where storing in the cache is not recommended because that is the first place iOs begins to trim down data when it gets low on storage.

So no one else has had this issue?

http://unity3d.com/support/documentation/ScriptReference/iPhone.SetNoBackupFlag.html

?

That is awesome! Thanks. Don’t know how I missed it.

If the data is marked as do not backup does that mean that if a person downloads an asset bundle for an in app purchase, that itunes will not back it up when it is synced? If so how does a person recover an in app purchase if their phone has to be restored?

Thanks,
Dan

Well you should offer a way to your user to redownload the inapp for free. I think a “restore” button is now mandatory.
http://forums.toucharcade.com/showthread.php?t=138893

But it shouldn’t work on consumable purchases.

Just as a clarification, and I realize this might be a dumb question, but:

the parameter path of iPhone.SetNoBackupFlag() is the name of the asset bundle file, right? For example: “samplebundle.unity3d” ? The reason I ask is because I can pass that as the parameter for something like Caching.IsVersionCached(url, version), and receive feedback, but I can’t check if the iPhone.SetNoBackupFlag(path) is being set correctly on my assetbundle.

@SirGive I just got rejected for this very same reason.

So all you did was use the iPhone.SetNoBackupFlag() and it fixed it? What string did you use for the path?

I really wish Unity iOS team would give us more info on this; I really don’t want to wait a week to test whether this works or not.

Any tips or advice would be appreciated.

Thank you!

WWW.LoadFromCacheOrDownload always sets “No Backup” flag for cached files. If you are caching files manually and storing them via .NET file API then you should set this flag from your code by calling iPhone.SetNoBackupFlag() and passing full path as an argument.

@Mantas-Puida We have a build which has been rejected by Apple. The asset bundle handling code did not change in this update, and we always used www.LoadFromCacheOrDownload. In fact the current live build which was built with 5.3.2p3 works fine (only 250k is being reported in iCloud storage from Settings app). The rejected build was done with Unity 5.3.3p1 which is trying to backup any downloaded asset bundles. The same erroneous behaviour is also present in builds done with 5.3.3p2.

Do we need to do something from our side, as from 5.3.3, to flag asset bundles to not be backed up?

@JoshPeterson Tagging you since this might be in your realm of IL2CPP team

@xenonmiii

Initially, I don’t think that this is specifically related to IL2CPP. I’ll watch this thread though for more updates and help out if I can.

We will look into that ASAP.

@Mantas-Puida We just checked Unity 5.3.3p3 just in case it was fixed, but the problem still occurs

Hello @xenonmiii ,
The fix will be coming next week in 5.3.4p1. For now you can modify FileSystem.mm to always set the no backup flag:

extern "C" int UnityUpdateNoBackupFlag(const char* path, int setFlag)
{
    int result;
    if (true) // if(setFlag)
    {
        u_int8_t b = 1;
        result = ::setxattr(path, "com.apple.MobileBackup", &b, 1, 0, 0);
    }
    else
    {
        result = ::removexattr(path, "com.apple.MobileBackup", 0);
    }
    return result == 0 ? 1 : 0;
}

This will make sure any asset bundles that are downloaded are flagged to not be backed up to iCloud. Let me know if you have any issues or further questions.
Cheers,
Chris

edit: I erroneously put 5.3.3p4 as the patch release when I first posted

@christophergoy Thanks for the temp fix. I confirm this works using the above edit.

@xenonmiii ,
Glad to hear it helps. Let me know if you run into any issues in the meantime.
Cheers,
Chris

When has this been merged into 5.4.0 beta? It was not yet fixed in Unity 5.4.0b3.

b3 sounds very old, latest beta is b14 at the moment.

Seems to be fixed in Unity 5.4.0b12 already (havn’t checked every single beta version, but b3 and b12).

Hey @mantikor ,
The fix has made it’s way to 5.3. It is still slowly making it’s way into 5.4. I will poke this thread once it has landed.
Thanks,
Chris

1 Like