Created
August 30, 2016 03:02
-
-
Save blacklee/59e8d4c2a2dff1cdf84823bfe1e9e68f to your computer and use it in GitHub Desktop.
Using this partial codes to share test data across all simulators in your Mac.
This file contains hidden or 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
- (void)setupSharedDirectoryForMacTest { | |
#ifndef DEBUG | |
return; | |
#endif | |
#ifndef TARGET_IPHONE_SIMULATOR | |
return; | |
#endif | |
NSLog(@"--------------------------------------------------------------------------------------------------------"); | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; | |
NSError *err; | |
NSString *macUser = [[documentPath componentsSeparatedByString:@"/"] objectAtIndex:2]; | |
NSString *sharedRoot = [[NSString stringWithFormat:@"/Users/%@/SIMULATOR/", macUser] stringByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier]]; | |
if (![fileManager fileExistsAtPath:sharedRoot]) { | |
[fileManager createDirectoryAtPath:sharedRoot withIntermediateDirectories:YES attributes:nil error:&err]; | |
assert(!err); | |
} | |
NSString *applicationSupportPath = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]; | |
if (![fileManager fileExistsAtPath:applicationSupportPath]) { | |
[fileManager createDirectoryAtPath:applicationSupportPath withIntermediateDirectories:YES attributes:nil error:&err]; | |
assert(!err); | |
} | |
NSString *applicationSupportPathForMainBundle = [applicationSupportPath stringByAppendingPathComponent:[NSBundle mainBundle].bundleIdentifier]; | |
NSString *logPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/Logs"]; | |
NSArray *dirs = @[ | |
documentPath, | |
applicationSupportPathForMainBundle, | |
logPath | |
]; | |
for (NSString *directory in dirs) { | |
NSLog(@"create symbolic link if needed: %@", directory); | |
if ([fileManager fileExistsAtPath:directory]) { | |
NSDictionary *attr = [fileManager attributesOfItemAtPath:directory error:&err]; | |
assert(!err); | |
if (![[attr fileType] isEqualToString:NSFileTypeSymbolicLink]) { | |
[fileManager removeItemAtPath:directory error:&err]; | |
assert(!err); | |
NSLog(@"REMOVE DIRECOTRY BECAUSE ITS TYPE IS: %@", [attr fileType]); | |
} | |
} | |
if (![fileManager fileExistsAtPath:directory]) { | |
[fileManager createSymbolicLinkAtPath:directory withDestinationPath:sharedRoot error:&err]; | |
assert(!err); | |
NSLog(@"CREATE SYMBOLIC LINK FOR %@", directory); | |
} | |
} | |
NSLog(@"--------------------------------------------------------------------------------------------------------"); | |
} | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[self setupSharedDirectoryForMacTest]; | |
...... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment