forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSURL+Common.m
More file actions
50 lines (45 loc) · 1.9 KB
/
NSURL+Common.m
File metadata and controls
50 lines (45 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// NSURL+Common.m
// Coding_iOS
//
// Created by Ease on 15/2/3.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#import "NSURL+Common.h"
#import <sys/xattr.h>
@implementation NSURL (Common)
+(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
if ([[NSFileManager defaultManager] fileExistsAtPath: [URL path]])
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.1")) {
NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey error: &error];
if(error){
DebugLog(@"addSkipBackupAttributeToItemAtURL: %@, error: %@", [URL lastPathComponent], error);
}
return success;
}
if (SYSTEM_VERSION_GREATER_THAN(@"5.0")) {
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;
}
}
return NO;
}
- (NSDictionary *)queryParams{
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *param in [[self query] componentsSeparatedByString:@"&"]) {
NSArray *elts = [param componentsSeparatedByString:@"="];
if([elts count] < 2) continue;
[params setObject:elts[1] forKey:elts[0]];
}
return params;
}
@end