Created
May 15, 2012 23:22
-
-
Save pixelrevision/2705937 to your computer and use it in GitHub Desktop.
ios writable directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface WritableDirectory : NSObject | |
+ (NSString*)getDir; | |
@end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "WritableDirectory.h" | |
@implementation WritableDirectory | |
+ (NSString*)getDir{ | |
static bool _createdWritableDir = true; | |
static NSString * _writableDirectory = NULL; | |
NSFileManager * fileManager = [NSFileManager defaultManager]; | |
if(_createdWritableDir) { | |
_createdWritableDir = false; | |
NSString * version = [[UIDevice currentDevice] systemVersion]; | |
if([version isEqualToString:@"5.0"]) { | |
_writableDirectory = [[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches"] copy]; | |
} else if([version floatValue] >= 5.0) { | |
_writableDirectory = [[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/NoBackup/"] copy]; | |
[fileManager createDirectoryAtPath:_writableDirectory withIntermediateDirectories:true attributes:nil error:nil]; | |
const char * attrName = "com.apple.MobileBackup"; | |
uint8_t attrValue = 1; | |
setxattr([_writableDirectory UTF8String],attrName,&attrValue,sizeof(attrValue),0,0); | |
} else { | |
_writableDirectory = [[NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/NoBackup/"] copy]; | |
[fileManager createDirectoryAtPath:_writableDirectory withIntermediateDirectories:true attributes:nil error:nil]; | |
} | |
} | |
return _writableDirectory; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment