addSkipBackupAttributeToItemAtURL -> NSString parameter?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 05:17:21

问题


In order to follow the Data Storage Guidelines I must use the below method to add a flag to say to not back it up to iCloud. However, the parameter here is for a NSURL. I need to pass it a NSString like from a line like so

return [[self offlineQueuePath] stringByAppendingPathComponent:@"SHKOfflineQueue.plist"];

Here is the method that takes in a URL.

    - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
        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;
    } else { // iOS >= 5.1
        NSError *error = nil;
        [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
        return error == nil;
    }
}

Anyway, how would I modify the method above to achieve the same while taking in a NSString as a parameter?

Thanks!


回答1:


You don't need to modify the method. Convert your string to URL.

NSURL *url = [NSURL URLWithString:@"your string"];



回答2:


Use this method

 NSURL *pathURL113= [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",Your string]];

this is perfect code.



来源:https://stackoverflow.com/questions/10591087/addskipbackupattributetoitematurl-nsstring-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!