Prevent files from being uploaded to Icloud-b

Source: Internet
Author: User
Tags file url home screen

Have time to use the

http://www.cocoachina.com/bbs/read.php?tid=86244

http://www.ooso.net/archives/617

http://blog.csdn.net/theonezh/article/details/7711749

https://gist.github.com/4527957

How can I prevent files from syncing with itunes and icloud how does I prevent files from being backed to ICloud and itunes?



With icloud in IOS 5, Apple has updated its data storage guidelines to accommodate icloud storage, while adding "do not back up" file attributes to specify that files are not backed up and uploaded to icloud

Excerpts are as follows, for your reference:

IOS Data Storage Guidelines

ICloud includes a backup that automatically backs up users ' iOS devices every day via Wi-Fi. Everything in the app's home directory will be backed up, in addition to the app bundle itself, the cache directory, and the temp directory. Purchased music, apps, books, Camera roll, device settings, home screen, app organization, messages, ringtones will also be backed up. Because backups are done wirelessly and stored in icloud for each user, the app needs to minimize the amount of data it stores. Large files can prolong backup times and consume the user's available icloud space.

To ensure that backups are as fast and efficient as possible, applying stored data requires the following guidelines:

1. Only those user-generated documents or other data, or data that the app cannot recreate, should be stored in the/documents directory and automatically backed up to icloud.

2. Data that can be re-downloaded or generated should be stored in the/library/caches directory. For example, database cache files, downloadable files (magazines, newspapers, data used by map applications), etc. are in this category.

3. Temporary use of data should be stored in the/tmp directory. Although these files will not be backed up by icloud, the app will need to remember to delete the files after use so that it does not continue to occupy the user's device space.

4. Use the Do not backup property to specify files that need to remain on the device, even if there is low storage space. This property is required for those files that can be regenerated, but remain in low storage space, have an impact on the app's uptime, or if the user wants files to be available offline. This property can be used regardless of the file (including the documents directory) in the directory. These files are not deleted and are not included in the user's icloud or itunes backup. Since these files always occupy the storage space of the user's device, it is the responsibility of the application to periodically monitor and delete these files.


IOS 5.0.1 begins to support the "do not back up" file properties, allowing developers to explicitly specify which files should be backed up, which local caches can be automatically deleted, and which files need not be backed up but not deleted. In addition, setting this property on the directory prevents all content in the directory and directory from being backed up.

Note the "Do not back to" property can only be used for iOS 5.0.1 later versions. Previous versions of the app need to store data to the/library/caches directory to avoid being backed up. Since the old system ignores this attribute, you need to make sure that the app is in all iOS versions and follows the iOS Data Storage guidelines above.

Data Processing Classification
The Com.apple.MobileBackup file property is an iOS 5.0.1 introduction to the "Do No Back Up" feature that specifies that a file or directory does not need to be backed up (regardless of where the file system is located). By using this new file attribute and storing the file in the specified directory, the file can be divided into the following four types of data: S.

Key Data
These are user-created data, or other data that cannot be regenerated. Should be stored in the/documents directory and should not be marked as a "do not backup" property. Critical data is retained in low storage space and is backed up by icloud or itunes.

Cache Data
Data that can be re-downloaded or generated without this data will not prevent users from using the app's functionality offline. The cached data should be stored in the/library/caches directory. Cached data may be deleted when the device is low on storage, and itunes or icloud will not back it up.

Temporary Data
Applications need to write to local storage, using temporary data internally, but do not need to be retained for long-term use. Temporary data should be saved in the/tmp directory. The system may empty the data in that directory, nor will itunes or icloud back it up. Applications that do not need to use this data should delete temporary data as soon as possible to avoid wasting the user's storage space.

Offline Data
can be downloaded or recreated, but users want to be able to access the data when they are offline. Offline data should be stored in the/documents directory or the/library/private documents directory and marked as a "do not backup" property. The data in both locations is preserved when the storage space is low, and the Do not backup property blocks itunes or icloud backups. When an app no longer needs an offline data file, it should be deleted as soon as possible to avoid wasting the user's storage space. Ce.

Setting the Do not backup extended property
Note: The "Do not backup" extended property can be added to any file or directory and can be set on older versions of the system. However, the old system will still back up these files, and once the device is updated to iOS 5.0.1, the files will be properly configured again.

Use the following method to set the do not back to extended property. When you create a file or directory that does not need to be backed up, write data to the file, and then call the following method and pass a file URL.

Set Extended Properties
#include
-(BOOL) Addskipbackupattributetoitematurl: (Nsurl *) URL
{
Const char* FilePath = [[URL path] filesystemrepresentation];
Const char* attrname = "Com.apple.MobileBackup";
u_int8_t attrValue = 1;

int result = Setxattr (FilePath, Attrname, &attrvalue, sizeof (AttrValue), 0, 0);
return result = = 0;
}



Apple has put new demands on the app's file storage when it comes to the iOS 5 system. From its guildline, it is recommended that developers try to put the app-generated files in the caches directory. The original text reads as follows:

Only user-generated data or cannot otherwise is recreated by your application, should is stored in the/documents dir Ectory and rest should be stored to/library/caches directory.

What happens when you do it?

If you do, there are two things.

    1. If you ignore this, continue to put the app generated files in the documents directory, then these files will be backed up to itunes or icloud. If these files are large, then the user may need to consume a lot of traffic in order to sync, and then Apple might reject your app shelves, which is a tragedy.
    2. If the developer does what Apple says and puts the app-generated files in the caches directory, Apple won't reject your app, and it's happy. But iOS 5 will remove files from the caches directory when disk space is tight, which could be a bigger tragedy for users.
How do I respond to a new file storage policy?

Developers are stuck in a dilemma, but when it comes to iOS 5.0.1, developers have a third choice:

    • Continue to store files in the documents directory, but mark these files as no backup required. For more information, please refer to Technote (QA1719)

The original text reads as follows:

The Q:my app has a number of files, need to being stored on the device permanently for My apps to function properly offline. However, those files do not contain the user data and don ' t need to being backed up. How should I store those files in IOS 5?

A:starting in IOS 5.0.1 a new "does not back up" file attribute have been introduced allowing developers to clearly specify Which files should is backed up, which files is local caches only and subject to purge, and which files should isn't be BAC Ked up but should also isn't be purged. In addition, setting this attribute on a folder would prevent the folder and all of its contents from being backed up.

code example

Add the code for the "Do not go up" property to the file as follows, and be aware that this is an iOS 5.0.1, which is less difficult than this version.

#include   - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL  {  const char* filePath = [[URL path] fileSystemRepresentation]; const char* attrName ="com.apple.MobileBackup"; u_int8_t attrValue = 1; int result = setxattr(filePath,attrName, &attrValue, sizeof(attrValue), 0, 0); return result == 0; }


//设置扩展属性

#include - ( BOOL )addSkipBackupAttributeToItemAtURL:( NSURL *)URL { const char * filePath = [[URL path] fileSystemRepresentation]; const char * attrName = "com.apple.MobileBackup" ; u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &attrValue, sizeof (attrValue), 0, 0); return result == 0; }

You can put the data in the Documents folder but the before keep in Documents folder create a folder within Documents folder suppose N amely temp. Then write the following code to not backup in ICloud.

[[Nsfilemanager Defaultmanager] Createdirectoryatpath:temp
Withintermediatedirectories:no
Attributes:nil
Error:nil];
Nsurl *dburlpath = [Nsurl urlwithstring:temp];
[Self addskipbackupattributetoitematurl:dburlpath];
Also Implement the method Addskipbackupattributetoitematurl do not forget to include
#include

-(BOOL) Addskipbackupattributetoitematurl: (Nsurl *) URL {
Const char* FilePath = [[URL path] filesystemrepresentation];

Const char* attrname = "Com.apple.MobileBackup";
u_int8_t attrValue = 1;

int result = Setxattr (FilePath, Attrname, &attrvalue, sizeof (AttrValue), 0, 0);
return result = = 0;
}

File classification, storage path, and file attributes for iOS

Key data

Content: User-created data files that cannot be recreated automatically after deletion and

Path: Home directory/documents

Properties: Do not set "do not back up"

Management: iOS systems are not purged when they are running out of storage space and are backed up to itunes or icloud

Cache data

Content: can be used for offline environment, can be repeated download duplicate generation, immediately when offline, the application itself can function

Path: Home directory/library/caches

Properties: Default

Management: Empty in case of insufficient storage space, and will not be automatically backed up to itunes and icloud

Temporary data

Content: Files that are temporarily generated for an internal operation when the app is run

Path: Home Directory/tmp

Properties: Default

Management: May be purged by iOS system at any time, and will not be automatically backed up to itunes and icloud, try to apply your own situation when the files are no longer in use, and avoid wasting on user device space.

Offline data

Content: Similar to cached data, it can be re-downloaded and rebuilt, but users tend to expect data to remain in place while offline

Directory: Home directory/documents or home directory/library/custom Folder

Properties: Do not need to set in documents, put in the custom folder should be set "do not Backup"

Management: Similar to critical data, it will not be clear when there is not enough storage space, the application should clean up files that are no longer used, so as not to waste user device space



Settings introduced from iOS5.0.1 do not back up files (folders also apply) Extended properties
From being backed to ICloud and iTunes? Category: iphone development 2012-03-23 11:28452 people read reviews (0) Favorites Report Read the official notes first:

https://developer.apple.com/library/ios/#qa/qa1719/_index.html How to use: #import "Sys/xattr.h"

-(BOOL) Addskipbackupattributetoitematurl: (Nsurl *) URL
{
Const char* FilePath = [[URL path] filesystemrepresentation];

Const char* attrname = "Com.apple.MobileBackup";
u_int8_t attrValue = 1;

int result = Setxattr (FilePath, Attrname, &attrvalue, sizeof (AttrValue), 0, 0);
return result = = 0;
}

-(void) Addskipbackupattributetopath: (nsstring*) path {
u_int8_t B = 1;
Setxattr ([path filesystemrepresentation], "Com.apple.MobileBackup", &b, 1, 0, 0);
}

Using either of these two methods with the path to the folder allows the directory and all files and folders contained in the directory not to be synced with icloud and itunes! For details on the design rules for synchronizing data, see the official note link above. Note: Setxattr does not work in systems prior to iOS 5.0.1 (but those systems do not have icloud only itunes^.^).  The test finds that although it does not work, calling the function does not cause a null pointer error. This is a very interesting technology: the new system added to the original system does not have the Func, in the original system call, incredibly no nullpoint error. Is this function address already exist, reserved good behind the function hangs? It's strange. In addition, the test of this feature should be patient, because the amount of data to be synchronized in the icloud recognition application is displayed in seconds (chrysanthemums). ), reference Document: Apple official documentation, StackOverflow question and answer: http://stackoverflow.com/questions/8694112/ Adding-the-do-not-backup-attribute-to-a-folder-hierarchy-in-ios-5-0-1

Prevent files from being uploaded to Icloud-b

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.