Skip to content

Commit

Permalink
Merge pull request #24 from adeven/development
Browse files Browse the repository at this point in the history
Check availability of NSURLIsExcludedFromBackupKey
  • Loading branch information
wellle committed Jan 13, 2014
2 parents 2ea996b + 25434af commit ec7431c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
4 changes: 2 additions & 2 deletions AdjustIO.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "AdjustIO"
s.version = "2.1.2"
s.version = "2.1.3"
s.summary = "This is the iOS SDK of AdjustIo. You can read more about it at http://adjust.io."
s.homepage = "http://adjust.io"
s.license = { :type => 'MIT', :file => 'MIT-LICENSE' }
s.author = { "Christian Wellenbrock" => "welle@adeven.com" }
s.source = { :git => "https://github.com/adeven/adjust_ios_sdk.git", :tag => "v2.1.2" }
s.source = { :git => "https://github.com/adeven/adjust_ios_sdk.git", :tag => "v2.1.3" }
s.platform = :ios, '4.3'
s.framework = 'AdSupport', 'SystemConfiguration'
s.source_files = 'AdjustIo/*.{h,m}', 'AdjustIo/AIAdditions/*.{h,m}'
Expand Down
40 changes: 32 additions & 8 deletions AdjustIo/AIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#import "AILogger.h"
#import "UIDevice+AIAdditions.h"

#include <sys/xattr.h>

static NSString * const kBaseUrl = @"https://app.adjust.io";
static NSString * const kClientSdk = @"ios2.1.2";
static NSString * const kClientSdk = @"ios2.1.3";


#pragma mark -
Expand Down Expand Up @@ -72,15 +74,37 @@ + (NSString *)sanitize:(NSString *)string defaultString:(NSString *)defaultStrin
return result;
}

// inspired by https://gist.github.com/kevinbarrett/2002382
+ (void)excludeFromBackup:(NSString *)path {
NSURL *url = [NSURL fileURLWithPath:path];
NSError *error = nil;
BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&error];

if (!success) {
[AILogger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription];
const char* filePath = [[url path] fileSystemRepresentation];
const char* attrName = "com.apple.MobileBackup";

if (&NSURLIsExcludedFromBackupKey == nil) { // iOS 5.0.1 and lower
u_int8_t attrValue = 1;
int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
if (result != 0) {
[AILogger debug:@"Failed to exclude '%@' from backup", url.lastPathComponent];
}
} else { // iOS 5.0 and higher
// First try and remove the extended attribute if it is present
int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0);
if (result != -1) {
// The attribute exists, we need to remove it
int removeResult = removexattr(filePath, attrName, 0);
if (removeResult == 0) {
[AILogger debug:@"Removed extended attribute on file '%@'", url];
}
}

// Set the new key
NSError *error = nil;
BOOL success = [url setResourceValue:[NSNumber numberWithBool:YES]
forKey:NSURLIsExcludedFromBackupKey
error:&error];
if (!success) {
[AILogger debug:@"Failed to exclude '%@' from backup (%@)", url.lastPathComponent, error.localizedDescription];
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you're using [CocoaPods][cocoapods], you can add the following line to your
`Podfile` and continue with [step 3](#step3):

```ruby
pod 'AdjustIO', :git => 'git://github.com/adeven/adjust_ios_sdk.git', :tag => 'v2.1.2'
pod 'AdjustIO', :git => 'git://github.com/adeven/adjust_ios_sdk.git', :tag => 'v2.1.3'
```

### 1. Get the SDK
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.2
2.1.3
6 changes: 3 additions & 3 deletions doc/migration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Migrate your AdjustIo SDK for iOS from v1.x to v2.1.2
## Migrate your AdjustIo SDK for iOS from v1.x to v2.1.3

1. Delete the old `AdjustIo` source folder from your Xcode project. Download
version v2.1.2 and drag the new folder into your Xcode project.
version v2.1.3 and drag the new folder into your Xcode project.

![][drag]

Expand Down Expand Up @@ -55,7 +55,7 @@
2. The `appDidLaunch` method now expects your App Token instead of your App ID.
You can find your App Token in your [dashboard].

2. The AdjustIo SDK for iOS 2.1.2 uses [ARC][arc]. If you haven't done already,
2. The AdjustIo SDK for iOS 2.1.3 uses [ARC][arc]. If you haven't done already,
we recommend [transitioning your project to use ARC][transition] as well. If
you don't want to use ARC, you have to enable ARC for all files of the
AdjustIo SDK. Please consult the [README] for details.
Expand Down

0 comments on commit ec7431c

Please sign in to comment.