Mac How do I disable sandboxing?

robvas

macrumors 68040
Original poster
Mar 29, 2009
3,045
511
USA
I am using the latest Xcode and latest MacOS, how do I disable sandboxing so I can access a users home directory?

I don't have the checkbox checked for Enable Sandboxing but I keep getting this directory instead of the users home dir:

file://localhost/Users/robert/Library/Developer/Xcode/DerivedData/Grab-azfpkhbwpmzueraynimpurcnwdvx/Build/Products/Debug/

This just started happening before I updated Xcode a week or two ago.
 

gnasher729

macrumors P6
Nov 25, 2005
16,823
3,636
I am using the latest Xcode and latest MacOS, how do I disable sandboxing so I can access a users home directory?

I don't have the checkbox checked for Enable Sandboxing but I keep getting this directory instead of the users home dir:

file://localhost/Users/robert/Library/Developer/Xcode/DerivedData/Grab-azfpkhbwpmzueraynimpurcnwdvx/Build/Products/Debug/

This just started happening before I updated Xcode a week or two ago.
Post your code.
 

robvas

macrumors 68040
Original poster
Mar 29, 2009
3,045
511
USA
Code:
- (void) saveCGImage:(CGImageRef)image {
  NSUserDefaults *defaults = [NSUserDefaults
															standardUserDefaults];
	time_t rawtime;
	struct tm *timeinfo;
	char buffer[80];
	
	time (&rawtime);
  timeinfo = localtime (&rawtime);
  strftime (buffer,80,[[defaults objectForKey:GRBFileNameString] cStringUsingEncoding:NSUTF8StringEncoding ],timeinfo);
	
	NSString *fName = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
	
//  NSString *screenShotFilePath = [NSString stringWithFormat:fName, NSHomeDirectory()];
	
	NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *docsDirectory = [paths objectAtIndex:0];

	NSString *screenShotFilePath = [NSString stringWithFormat:fName, docsDirectory];

	NSLog(@"path = %@", screenShotFilePath);
  
  [self CGImageWriteToFile:image filePath:screenShotFilePath];
}

- (void) CGImageWriteToFile:(CGImageRef)image filePath:(NSString*)path {
  CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:path];
  
  NSLog(@"url = %@ END", url);
  
  CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, NULL);
  CGImageDestinationAddImage(destination, image, nil);
  
  if (!CGImageDestinationFinalize(destination)) {
    NSLog(@"Failed to write image to %@", path);
  }
  
  CFRelease(destination);
}
Output:

2012-09-30 17:42:47.045 Grab[4892:303] path = CAPTURE-09-30-2012.PNG
2012-09-30 17:42:47.046 Grab[4892:303] url = CAPTURE-09-30-2012.PNG -- file://localhost/Users/robert/Library/Developer/Xcode/DerivedData/Grab-azfpkhbwpmzueraynimpurcnwdvx/Build/Products/Debug/ END
 

robvas

macrumors 68040
Original poster
Mar 29, 2009
3,045
511
USA
Ahhh nevermind I figured it out - building the path wrong, the functions return what they should.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.