addSkipBackupAttributeToItemAtURL – > NSString参数?
为了遵循数据存储指南,我必须使用下面的方法添加一个标志来说明不支持iCloud。 但是,这里的参数是NSURL的。 我需要像这样从一行传递一个NSString
return [[self offlineQueuePath] stringByAppendingPathComponent:@"SHKOfflineQueue.plist"];
这是接收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作为参数?
谢谢!
您不需要修改该方法。 将您的string转换为URL。
NSURL *url = [NSURL URLWithString:@"your string"];
使用这种方法
NSURL *pathURL113= [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@",Your string]];
这是完美的代码。