为了遵循数据存储指南,我必须使用以下方法添加一个标志,表示不备份到iCloud。但是,此处的参数适用于NSURL。我需要传递一个类似于
这样的行的NSStringreturn [[self offlineQueuePath] stringByAppendingPathComponent:@"SHKOfflineQueue.plist"];
以下是接收网址的方法。
- (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作为参数时,如何修改上述方法以实现相同目的?
谢谢!
答案 0 :(得分:2)
您无需修改方法。将您的字符串转换为URL。
NSURL *url = [NSURL URLWithString:@"your string"];
答案 1 :(得分:0)
使用此方法
NSURL *pathURL113= [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",Your string]];
这是完美的代码。