Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

iOs and asset bundles?

Discussion in 'iOS and tvOS' started by SirGive, Apr 12, 2012.

  1. SirGive

    SirGive

    Joined:
    Sep 27, 2010
    Posts:
    384
    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: https://developer.apple.com/icloud/documentation/data-storage/

    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.
     
    Last edited: Apr 12, 2012
  2. SirGive

    SirGive

    Joined:
    Sep 27, 2010
    Posts:
    384
    So no one else has had this issue?
     
  3. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
  4. SirGive

    SirGive

    Joined:
    Sep 27, 2010
    Posts:
    384
    That is awesome! Thanks. Don't know how I missed it.
     
  5. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    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
     
  6. Wild-Factor

    Wild-Factor

    Joined:
    Oct 11, 2010
    Posts:
    607
    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.
     
  7. Vaklav

    Vaklav

    Joined:
    Sep 27, 2012
    Posts:
    6
    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.
     
  8. robotmechanic

    robotmechanic

    Joined:
    Dec 29, 2009
    Posts:
    106
    @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!
     
  9. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    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.
     
  10. xenonmiii

    xenonmiii

    Joined:
    Aug 2, 2010
    Posts:
    147
    @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
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    @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.
     
  12. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    We will look into that ASAP.
     
  13. xenonmiii

    xenonmiii

    Joined:
    Aug 2, 2010
    Posts:
    147
    @Mantas Puida We just checked Unity 5.3.3p3 just in case it was fixed, but the problem still occurs
     
  14. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    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:

    Code (CSharp):
    1. extern "C" int UnityUpdateNoBackupFlag(const char* path, int setFlag)
    2. {
    3.     int result;
    4.     if (true) // if(setFlag)
    5.     {
    6.         u_int8_t b = 1;
    7.         result = ::setxattr(path, "com.apple.MobileBackup", &b, 1, 0, 0);
    8.     }
    9.     else
    10.     {
    11.         result = ::removexattr(path, "com.apple.MobileBackup", 0);
    12.     }
    13.     return result == 0 ? 1 : 0;
    14. }
    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
     
    Last edited: Mar 15, 2016
  15. xenonmiii

    xenonmiii

    Joined:
    Aug 2, 2010
    Posts:
    147
    @christophergoy Thanks for the temp fix. I confirm this works using the above edit.
     
  16. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    @xenonmiii,
    Glad to hear it helps. Let me know if you run into any issues in the meantime.
    Cheers,
    Chris
     
  17. ChimeraIT

    ChimeraIT

    Joined:
    May 9, 2014
    Posts:
    25
    When has this been merged into 5.4.0 beta? It was not yet fixed in Unity 5.4.0b3.
     
  18. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    b3 sounds very old, latest beta is b14 at the moment.
     
  19. ChimeraIT

    ChimeraIT

    Joined:
    May 9, 2014
    Posts:
    25
    Seems to be fixed in Unity 5.4.0b12 already (havn't checked every single beta version, but b3 and b12).
     
  20. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    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
     
    ChimeraIT likes this.
  21. benacler

    benacler

    Joined:
    Oct 26, 2013
    Posts:
    6
    Could we know where the problem was ? On 5.3.3 we are downloading asset bundles manually into Application. temporaryCachePath and setting the file with the SetNoBackupFlag function, and still hit the problem with Apple. We are not in the process of changing version and are trying the Filesystem.mm hack falling back to WWW.LoadFromCacheOrDownload , but would like to keep our old system, so the problem was with the SetNoBackupFlag or else where in the WWW class ? Because it has no sense otherwise.
     
  22. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
    The problem was at cache management logic level in context of how lower level functions handle this flag. Basically when downloaded files were transferred from temp location to cache folder it accidentally was resetting this flag. So hacked version of FileSystem.mm just prevents resetting of this flag as it ignores argument passed to it. It should be ok as temporal solution if you can't update Unity.
     
  23. Luffy19901222

    Luffy19901222

    Joined:
    May 13, 2015
    Posts:
    2
    My Unity is 5.3.4f1, And I still have this Question. I use www.LoadFromCacheOrDownload to load Asset bundle.
     
  24. TimKofoed

    TimKofoed

    Joined:
    Aug 9, 2012
    Posts:
    6
    I can confirm that the bug is still present in the most recent 5.3.4f1.
    I just had an app rejected because of it, and when I use the provided Filesystem.mm hack, my iCloud usage drops from 50Mb to 0.1kb.

    I am using Application.streamingAssetsPath to access included AssetBundles, which I load using LoadFromCacheOrDownload.
    I am not downloading anything from the web, and I am not accessing either the temporaryCachePath or persistentDataPath.
     
  25. Mantas-Puida

    Mantas-Puida

    Joined:
    Nov 13, 2008
    Posts:
    1,864
  26. TimKofoed

    TimKofoed

    Joined:
    Aug 9, 2012
    Posts:
    6
    I stand corrected. It is working as intended in 5.3.4p5.
    Thanks.

    I didn't know that was a place I should look for even newer releases.
    From a usability perspective, I don't expect to look on the right side of the download page, because I associate those links with older or peripheral resources.

    I would recommend a sentence below the "Download Installer"; "Found a bug? Check Patch Releases"... or something similar.
     
  27. FridgeWalaby

    FridgeWalaby

    Joined:
    Mar 6, 2016
    Posts:
    4
    I'm dealing with the same rejection issue, due to some data that is stored in the Documents directory which is getting stored or backed up on iCloud which then does not comply with the guidelines.

    The user can't create any data in my app that should be stored in the Documents directory.

    I could try to submit it with the hack version in Filesystem.mm...
     
  28. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @FridgeWalaby,
    The fix for this was released in Unity 5.3.4p1. If you download the patch release, this issue is fixed as @Mantas Puida stated here:
    Let me know if you run into any issues.
    Cheers,
    Chris
     
  29. TimKofoed

    TimKofoed

    Joined:
    Aug 9, 2012
    Posts:
    6
    As I understand it, you mean that your user doesn't have any option to make anything in your app, correct?
    If the data you want stored can be recreated by you at any point, then don't save to the Documents folder. The default for the Documents folder is to backup everything to iCloud, unless you set the noBackup flag.
    You should be saving to Application.temporaryCachePath instead.
     
  30. FridgeWalaby

    FridgeWalaby

    Joined:
    Mar 6, 2016
    Posts:
    4
    Thank you for your replies!

    @christophergoy
    I hope the patch does not mess up my unity project. I will get back to you as soon as I installed the patch.
    It'd be great if that fixes the problem.


    @TimKofoed
    Where exactly is the location in Unity to set the directory where data should be stored. Or is this a thing you have to decide manually in Xcode?
    My project is a game which is a standalone game, so there is no need to store any data outside the app (Documents).

    Thank you.
     
  31. TimKofoed

    TimKofoed

    Joined:
    Aug 9, 2012
    Posts:
    6
    @FridgeWalaby If you just make a game in Unity, which doesn't make or save data such as a text file, save file, new levels or assets from a server etc., then you will not be saving anything to the Documents folder at all.

    As a rule-of-thumb, if you save data which the user made, then save to Documents folder (persistentDataPath), which will be backed up in iCloud.
    If you save data your app needs, which you can download at any time from a server you own, if it gets deleted locally, then use the Cache folder (temporaryCachePath).

    When you make a normal project, it will save everything in the project itself, which is the Application.dataPath, which will become read-only when you make and build the project.

    If you want to manually save something like a save-file or a screenshot, then you might use http://docs.unity3d.com/ScriptReference/Windows.File.WriteAllBytes.html
    and give it the path (Application.persistentDataPath + "myFolder/" + "screenshot.png") and pass the image along as a byte array.
    You don't have to worry about where PlayerPrefs saves its data.

    If you are not manually saving anything to any of the save paths, then just download Unity 5.3.4p5, and it'll be fine. There's no need for any hack or fix. It works the way it's supposed to. You also don't have to do anything in XCode whether you manually save anything or not.
    http://unity3d.com/unity/qa/patch-releases
     
  32. benacler

    benacler

    Joined:
    Oct 26, 2013
    Posts:
    6
    So can you confirm me that even the SetNoBackupFlag is broken ? Because is seems so.