UIActivityViewController

Wongbing·2022년 10월 12일
0

Apple Docs

목록 보기
5/11

UIActivityViewController

Apple Docs - UIActivityViewController

tags: TIL

A view controller that you use to offer standard services from your app.

보통 앱에 표준서비스를 제공하는 뷰 컨트롤러

Declaration

class UIActivityViewController: UIViewController

Overview

The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

시스템은 몇몇의 표준서비스(복사, 소셜미디어사이트에 게시, 이메일 /문자를 통해 보내기 등등)를 제공합니다. 앱은 또한 커스텀서비스를 정의할 수 있습니다.

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act.

앱은 이 뷰컨트롤러를 구성하고, 나타내고, dismiss 하는 것에 책임이 있습니다. 뷰컨트롤러 구성은 뷰컨트롤러가 수행해야하는 데이터 객체를 지정하는 것을 포함합니다.

(You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.

(또한 앱이 지원하는 커스텀 서비스들을 지정할 수도 있습니다.) 뷰컨트롤러를 나타낼 때, 현재 디바이스에 적절한 방법을 이용해야 합니다. iPad에서는 popover로 나타내고, iPhone과 iPod touch에서는 present it modally로 나타냅니다.

예시코드

func generateShareAction(with indexPath: IndexPath) -> UIContextualAction {
    let shareAction = UIContextualAction(style: .normal, title: NameSpace.share) { _, _, _ in
        let model = CoreDataManager.shared.fetchedDiaries
        let title = model[indexPath.row].title ?? NameSpace.noneTitle
        let body = model[indexPath.row].body ?? NameSpace.noneTitle
        let diaryToShare: [Any] = [MyActivityItemSource(title: title, 
                                                        text: body)]
        let activityViewController = UIActivityViewController(
            activityItems: diaryToShare, 
            applicationActivities: nil
        )
        activityViewController.popoverPresentationController?.sourceView = self.diaryListView

        self.present(activityViewController, animated: true)
    }
    shareAction.image = UIImage(systemName: SystemName.shareIcon)
    shareAction.backgroundColor = .init(red: 80/255, green: 188/225, blue: 223/225, alpha: 1)
    return shareAction
}
profile
IOS 앱개발 공부

0개의 댓글