Skip to content

Commit

Permalink
Merge pull request ShareKit#368 from Objective-Zero/master
Browse files Browse the repository at this point in the history
flushOfflineQueue causes App Rejection
  • Loading branch information
scompt committed May 26, 2012
2 parents 7feb62a + 7abc14c commit a9429b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Classes/ShareKit/Core/SHK.h
Expand Up @@ -123,3 +123,9 @@ NSString * SHKEncodeURL(NSURL * value);
NSString * SHKFlattenHTML(NSString * value, BOOL preserveLineBreaks);
NSString * SHKLocalizedString(NSString* key, ...);
void SHKSwizzle(Class c, SEL orig, SEL newClassName);

@interface NSFileManager (DoNotBackup)

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;

@end
28 changes: 26 additions & 2 deletions Classes/ShareKit/Core/SHK.m
Expand Up @@ -36,6 +36,7 @@
#import <objc/runtime.h>
#import <objc/message.h>
#import <MessageUI/MessageUI.h>
#include <sys/xattr.h>

NSString * SHKLocalizedStringFormat(NSString* key);
NSString * const SHKHideCurrentViewFinishedNotification = @"SHKHideCurrentViewFinished";
Expand Down Expand Up @@ -534,15 +535,19 @@ + (NSString *)offlineQueuePath
NSString *SHKPath = [cache stringByAppendingPathComponent:@"SHK"];

// Check if the path exists, otherwise create it
if (![fileManager fileExistsAtPath:SHKPath])
if (![fileManager fileExistsAtPath:SHKPath]) {
[fileManager createDirectoryAtPath:SHKPath withIntermediateDirectories:YES attributes:nil error:nil];
[[NSFileManager defaultManager] addSkipBackupAttributeToItemAtURL:[NSURL URLWithString:SHKPath]];
}

return SHKPath;
}

+ (NSString *)offlineQueueListPath
{
return [[self offlineQueuePath] stringByAppendingPathComponent:@"SHKOfflineQueue.plist"];
NSString *offlinePathString = [[self offlineQueuePath] stringByAppendingPathComponent:@"SHKOfflineQueue.plist"];
[[NSFileManager defaultManager] addSkipBackupAttributeToItemAtURL:[NSURL URLWithString:offlinePathString]];
return offlinePathString;
}

+ (NSMutableArray *)getOfflineQueueList
Expand Down Expand Up @@ -788,3 +793,22 @@ void SHKSwizzle(Class c, SEL orig, SEL newClassName)

return string;
}

@implementation NSFileManager (DoNotBackup)

- (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
return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}

@end

0 comments on commit a9429b1

Please sign in to comment.