How do I disable sandboxing?

Discussion in 'Mac Programming' started by robvas, Sep 30, 2012.

  1. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #1
    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.
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Post your code.
     
  3. robvas thread starter macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #3
    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
     
  4. robvas thread starter macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #4
    Ahhh nevermind I figured it out - building the path wrong, the functions return what they should.
     

Share This Page