本文介绍了addSkipBackupAttributeToItemAtURL-> NSString参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了遵循数据存储准则,我必须使用以下方法添加一个标志,说不要将其备份到iCloud.但是,此处的参数用于NSURL.我需要像这样在一行中传递一个NSString
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"];
这是采用URL的方法.
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;
}
}
无论如何,当我将NSString作为参数时,我将如何修改上述方法以实现相同的目的?
谢谢!
推荐答案
您不需要修改方法.将您的字符串转换为URL.
You don't need to modify the method. Convert your string to URL.
NSURL *url = [NSURL URLWithString:@"your string"];
这篇关于addSkipBackupAttributeToItemAtURL-> NSString参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!