iDev/Mac Dev

OSX에서 현재 화면 캡쳐 및 트위터 공유하는 방법

KraZYeom 2014. 2. 18. 23:14
반응형

게임이 끝나고 OS X 내장된 트위터를 통해서 점수를 보낼 때, 현재 화면을 캡쳐해서 NSImage로 저장하는 방법이다. 


// 42는 윈도우 타이틀바 높이인데 뭔가 가져올 방법이 있을지도. 

방법 찾았음. 윈도우의 전체 크기에서 콘텐츠 크기를 빼면 됨. 42가 아니고 22였음. 


* 참조 

http://codereview.stackexchange.com/questions/32466/reviewing-c-function-which-captures-the-screen

http://adcdownload.apple.com//wwdc_2012/wwdc_2012_session_pdfs/session_306__integrating_with_facebook_twitter_and_sina_weibo.pdf


- (void)showServicePicker:(id)sender {

  NSRect frame = [[self.view window] frame];


  NSRect contentBounds = [[[self.view window] contentView] bounds];

  

  NSRect titlebarRect = NSMakeRect(0, 0, self.view.bounds.size.width, frame.size.height - contentBounds.size.height);


  frame.size.height = frame.size.height - titlebarRect.size.height;;

  frame.origin.y = frame.origin.y + titlebarRect.size.height;

  

  CGImageRef imageRef = CGWindowListCreateImage(frame, kCGWindowListOptionIncludingWindow|kCGWindowListOptionOnScreenOnly, 0, kCGWindowImageDefault);

  

  NSImage *image = [[NSImage alloc] initWithCGImage:imageRef size:frame.size];

  

  if (imageRef) {

    CFRelease(imageRef);

  }

  

  NSString *scoreString = [NSString stringWithFormat:@"Just scored %ld. ", (long)_score];

  NSArray *items = @[scoreString, image];

  NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNamePostOnTwitter];

  [service performWithItems:items];

}



* 의문점

Map App Store은 내장 프레임워크를 사용해서 소셜 공유를 하고, 왜 iTunes는 왜 웹으로 공유를 하는 것일까? Windows 용이 있어서 그런것일까? 맥용에만 프레임워크 적용해서 공유하게 해줬으면 하는 바람.

반응형