Search code examples
iosobjective-cmacoscocoamacos-carbon

How to get screen shoots from ios simulator in my app


if ios simulator is active,

how to send any message to ios simulator got screen shoot and stored in clipboard (have shortcut in ios simulator)

and i get from clipboard this screen shoot

in short, how to get screen shoot from ios simulator with objective-c

i need more objective c recources for communication between mac os apps,

Thanks


Solution

  • try this

     #import <QuartzCore/QuartzCore.h>
    
    - (void)viewDidLoad
    {
           [super viewDidLoad];
           UIGraphicsBeginImageContext(self.view.bounds.size);
           [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
           UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
           UIGraphicsEndImageContext();
           NSData * data = UIImagePNGRepresentation(image);
           NSArray *arrPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString *filePath = [[arrPath objectAtIndex:0] stringByAppendingPathComponent:@"test.png"];
           NSLog(@"%@",filePath);
          [data writeToFile:filePath atomically:YES];
    }