Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6286] iOS: "do not back up" flag for iOS 5.0.1

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-11-29T20:00:55.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sSprint 2011-48, Release 1.7.6, Release 1.8.0.1
ComponentsiOS
Labelsn/a
ReporterQing Gao
AssigneeStephen Tramer
Created2011-11-22T16:59:22.000+0000
Updated2011-12-16T10:42:35.000+0000

Description

iOS 5.0.1 introduces a new "do not back up" file attribute allowing developers to clearly specify which files should be backed up, which files are local caches only and subject to purge. Our Ti SDK should provide a new function to set this flag for iOS 5.0.1 devices. Reference: http://developer.apple.com/library/ios/#qa/qa1719/_index.html

Associated HelpDesk Ticket

http://appc.me/c/APP-316734

Test

NOTE: This test will not work on apps compiled for device in TiStudio; you will need to change the file to a non-application resources (no .js or .html) to check the bit toggle on it. Creating a stubbed out file with touch to include as a resource should be OK.
var win = Ti.UI.createWindow({backgroundColor:'white'});

var file = Ti.Filesystem.getFile('app.js');

var b = Ti.UI.createButton({
	height:60,
	width:200,
	title:"Toggle backup"
});

b.addEventListener('click', function() {
	try {
		var backup = file.remoteBackup;
		Ti.API.info("Remote backup: "+backup);
		file.remoteBackup = !backup;
	}
	catch (e) {
		Ti.API.info("ERROR: "+e);
	}
});

win.add(b);
win.open();

Comments

  1. Brian Caufield 2011-11-29

    I think this feature should be included in the 1.8.0 release considering that this issue either prevents applications from getting accepted by the app store (due to storing data in the documents folder w/o a DNBU flag), or alternatively risks the complete loss of app data by forcing the app to store data in the "Caches" folder which is the only location that doesn't get backed up and as such, is the only location where it is OK to store data w/o this flag.
  2. heenok 2011-11-29

    This is a big problem. My clients are waiting for an apple validation and with this issue i have no solution to give. Could we have a workaround soon ? Thanks
  3. Jeevan Takhar 2011-11-29

    Co-sign 1.8.0 urgency.
  4. Blain Hamon 2011-11-29

    Okay, a better test and a means to verify:
       var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mydir');
       Ti.API.info("Created mydir: " + newDir.createDirectory());
       Ti.API.info('newdir ' + newDir);
       var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'backup.txt');
       newFile.write("I should be backed up!");
       newFile.remoteBackup = true;
       
       var newFile2 = Titanium.Filesystem.getFile(newDir.nativePath,'dontbackup.txt');
       newFile2.write("I should NOT be backed up!");
       newFile2.remoteBackup = false;
       
    Verify: Go to the folder in question, eg "~/Library/Application Support/iPhone Simulator/5.0/Applications/69AB55BF-3B49-40CB-8510-E083629724E8/Documents/mydir" and run the following command:
       xattr -p -x "com.apple.MobileBackup" *
       
    You should see:
       backup.txt: 
       00
       dontbackup.txt: 
       01
       
  5. Brian Caufield 2011-11-30

    Thanks Blain, this seems to be working with the 1.8.0.1.v20111129200258 build. A couple of questions: 1) Is it sufficient to set just the folder's remoteBackup flag or will each file need to have it's remoteBackup attribute set? 2) Do we need to set this flag for the app's property list file in the Documents/Preferences folder too? I would actually prefer if this was backed up but I don't know if Apple's guidelines allow it. 3) Same for the app log file in the root of the Documents folder; does this need the remoteBackup flag too? Thanks again for all your help, Brian Caufield
  6. Stephen Tramer 2011-11-30

    Brian - Apple's technical note does not state anywhere whether this property is recursive or not. You should contact them for these details.
  7. Brian Caufield 2011-11-30

    Re: Question #1 - after some testing, it appears that when the remoteBackup flag is applied to a folder, it will prevent the backup of all the files it contains.
  8. Qing Gao 2011-12-05

    According to http://developer.apple.com/library/ios/#qa/qa1719/_index.html, there is line saying "In addition, setting this attribute on a folder will prevent the folder and all of its contents from being backed up." The remoteBackup flag in TiSDK sets the same attribute to either a folder or a file. So for Question #1, Yes, it is sufficient to just set the folder's flag. If I modify Blain's sample a little bit,
       var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mydir');
       Ti.API.info("Created mydir: " + newDir.createDirectory());
       Ti.API.info('newdir ' + newDir);
       
       var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'backup.txt');
       newFile.write("I should be backed up!");
       newDir.remoteBackup = true;
       
    you can see the folder's attribute is:
       mydir: 
       00
       
  9. heenok 2011-12-16

    Does we have to install iOs SDK 5.0.1 to check this folder's attribute ? thanks.
  10. Stephen Tramer 2011-12-16

    This attribute only works on iOS 5.0.1 and higher, so if you want to check behavior, yes.
  11. Natalie Huynh 2011-12-16

    Pass: Tested with 1.8.0.1.v20111216011148 on iPhone 4s (5.0.1) Simulator (5.0)

JSON Source