FBScreenshotCommands.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import "FBScreenshotCommands.h"
  10. #import "XCUIDevice+FBHelpers.h"
  11. @implementation FBScreenshotCommands
  12. #pragma mark - <FBCommandHandler>
  13. + (NSArray *)routes
  14. {
  15. return
  16. @[
  17. [[FBRoute GET:@"/screenshot"].withoutSession respondWithTarget:self action:@selector(handleGetScreenshot:)],
  18. [[FBRoute GET:@"/screenshot"] respondWithTarget:self action:@selector(handleGetScreenshot:)],
  19. ];
  20. }
  21. #pragma mark - Commands
  22. + (id<FBResponsePayload>)handleGetScreenshot:(FBRouteRequest *)request
  23. {
  24. NSError *error;
  25. NSData *screenshotData = [[XCUIDevice sharedDevice] fb_screenshotWithError:&error];
  26. if (nil == screenshotData) {
  27. return FBResponseWithStatus([FBCommandStatus unableToCaptureScreenErrorWithMessage:error.description traceback:nil]);
  28. }
  29. NSString *screenshot = [screenshotData base64EncodedStringWithOptions:0];
  30. return FBResponseWithObject(screenshot);
  31. }
  32. @end