[iOS] file share in iOS8

파일 공유를 위해 share 버튼을 추가한다.

UIBarButtonItem *openBtn = [[UIBarButtonItem alloc] initWithTitle:@"Open.." style:UIBarButtonItemStylePlain target:self action:@selector(showFileList:)];
self.shareBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share:)];
self.navigationItem.leftBarButtonItems = @[openBtn, self.shareBtn];

 

-(IBAction)share:(id)sender
{
  NSURL *url = [NSURL fileURLWithPath:self.selectedFilePath];
  UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
  [self presentViewController:controller animated:YES completion:nil];
  
  if ([controller respondsToSelector:@selector(popoverPresentationController)])
  {
    UIView *view = (UIView*)[self.shareBtn performSelector:@selector(view)];
    UIPopoverPresentationController *presentationController = [controller popoverPresentationController];
    presentationController.sourceView = view;
    presentationController.sourceRect = view.bounds;
    presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
  }
}

 

screenshot_2014-11-02_PM 10.43.05

 

어려운 기능인 것 같아서 안하고 있었는데, 이렇게 쉬운거면 진작 추가할걸 그랬네 ;;;;;