|
10 | 10 | #import "AILogger.h" |
11 | 11 | #import "UIDevice+AIAdditions.h" |
12 | 12 |
|
| 13 | +#include <sys/xattr.h> |
| 14 | + |
13 | 15 | static NSString * const kBaseUrl = @"https://app.adjust.io"; |
14 | | -static NSString * const kClientSdk = @"ios2.1.2"; |
| 16 | +static NSString * const kClientSdk = @"ios2.1.3"; |
15 | 17 |
|
16 | 18 |
|
17 | 19 | #pragma mark - |
@@ -72,15 +74,37 @@ + (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultStrin |
72 | 74 | return result; |
73 | 75 | } |
74 | 76 |
|
| 77 | +// inspired by https://gist.github.com/kevinbarrett/2002382 |
75 | 78 | + (void)excludeFromBackup:(NSString *)path { |
76 | 79 | NSURL *url = [NSURL fileURLWithPath:path]; |
77 | | - NSError *error = nil; |
78 | | - BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES] |
79 | | - forKey:NSURLIsExcludedFromBackupKey |
80 | | - error:&error]; |
81 | | - |
82 | | - if (!success) { |
83 | | - [AILogger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription]; |
| 80 | + const char* filePath = [[url path] fileSystemRepresentation]; |
| 81 | + const char* attrName = "com.apple.MobileBackup"; |
| 82 | + |
| 83 | + if (&NSURLIsExcludedFromBackupKey == nil) { // iOS 5.0.1 and lower |
| 84 | + u_int8_t attrValue = 1; |
| 85 | + int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); |
| 86 | + if (result != 0) { |
| 87 | + [AILogger debug:@"Failed to exclude '%@' from backup", url.lastPathComponent]; |
| 88 | + } |
| 89 | + } else { // iOS 5.0 and higher |
| 90 | + // First try and remove the extended attribute if it is present |
| 91 | + int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0); |
| 92 | + if (result != -1) { |
| 93 | + // The attribute exists, we need to remove it |
| 94 | + int removeResult = removexattr(filePath, attrName, 0); |
| 95 | + if (removeResult == 0) { |
| 96 | + [AILogger debug:@"Removed extended attribute on file '%@'", url]; |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + // Set the new key |
| 101 | + NSError *error = nil; |
| 102 | + BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES] |
| 103 | + forKey:NSURLIsExcludedFromBackupKey |
| 104 | + error:&error]; |
| 105 | + if (!success) { |
| 106 | + [AILogger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription]; |
| 107 | + } |
84 | 108 | } |
85 | 109 | } |
86 | 110 |
|
|
0 commit comments