backing up prevent from the app in iCloud

前端 未结 2 1804
自闭症患者
自闭症患者 2021-01-03 09:23

The way apple storage guidelines is creating more problem for me because most of the data i am maintaining from the Documents directory (files,dataBase and some kind of app

相关标签:
2条回答
  • 2021-01-03 09:35

    Use this function

    -(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
    {
    const char* filePath = [[URL path] fileSystemRepresentation];
    const char* attrName = "com.apple.MobileBackup";
    if (&NSURLIsExcludedFromBackupKey == nil) {
        // iOS 5.0.1 and lower
        u_int8_t attrValue = 1;
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return result == 0;
    
    }
    else {
        // First try and remove the extended attribute if it is present
        int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
        if (result != -1) {
            // The attribute exists, we need to remove it
            int removeResult = removexattr(filePath, attrName, 0);
            if (removeResult == 0) {
                NSLog(@"Removed extended attribute on file %@", URL);
            }
        }
    
        // Set the new key
        NSError *error = nil;
        [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
        return error == nil;
    }
     }
    

    this is implemeted code.thanks

    0 讨论(0)
  • 2021-01-03 09:51

    You should be able to set this attribute to a folder in order to avoid backup of the complete folder.

    Note however that it might noch be a good approach to do this to the complete Documents folder. First of all this will create a situation where you're app has no backed-up content thus on a restore of the phone the App will be in vanilla state. I could also imagine that this just is not the way "as Apple intended" and thus could lead to rejection of the app (always a guesswork). If possible, I would create a subfolder for your non-backed-up content in the Document directory and put everything there (this might need some migration code though if you already have a version of this app on the store).

    Note that the storage guidelines do allow storage of user-created / non-recreatable content in the Documents directory and you only have to mark things like downloaded content etc. that you cannot put in the Caches directory (for example if the user expects this content to be available offline).

    0 讨论(0)
提交回复
热议问题