Search

[실험실] Action Extension 겉핥기

Extension

Extension은 앱 패키지 안에 들어있지만, 앱과는 독립적인 객체의 개념
↔ 익스텐션으로의 이동
기본적으로 앱 안에 들어있기에 설치/삭제는 함께되지만, 동작은 별개
익스텐션은 익스텐션을 가진 앱과는 별개의 개념
만약 데이터를 공유해야 한다면, 이를 지원하는 것이 App Groups → App Groups가 같이 선택되어 있다면 앱과 익스텐션간의 데이터 교환이 가능
폰 DB 개념인 UserDefault, 파일 단위의 FileManager를 통한 접근 가능

MobileCoreServices

Uniform type identifier(UTI) 정보를 MobileCoreServices를 이용해서 현재 앱과 다른 앱(서비스) 사이에서 교환할 수 있는 데이터를 생성하고 작동시키기 위해 사용합니다.
더 알아보고 싶었지만 존재하지 않네요..

Share

import UIKit import Social class ShareViewController: SLComposeServiceViewController { override func isContentValid() -> Bool { // Do validation of contentText and/or NSExtensionContext attachments here return true } override func didSelectPost() { // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context. self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil) } override func configurationItems() -> [Any]! { // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. return [] } }
Swift
복사
Social : 표준 시스템 인터페이스를 사용하여 지원되는 소셜 네트워킹 서비스에 콘텐츠를 게시합니다
iOS에서만 Social Framework는 사용자를 대신하여 요청을 게시하기 위한 일반화된 인터페이스를 제공
Create a network session
Get the activity feed for a user
Make a new post
Set properties on a post, add attachments, etc.
Publish a post to an activity feed.
isContentVaild()
사용자가 Compose View에 텍스트를 입력할 때마다 호출
→ 이 메소드는 오른쪽 상단의 Post버튼의 활성화 여부를 결정합니다.
true : 활성화
false : 비활성화
📖
text를 가져오는 방식 ShareViewController는 SLComposeServiceViewController를 상속받고 있습니다. SLComposeServiceViewController 안에는 TextView가 들어있습니다. self.textView.text 라고 써도 되지만 contentText라는 String 속성을 만들어줬기 때문에 해당 속성을 가져다가 쓰면 됩니다. placeholder도 제공됩니다.
override func isContentValid() -> Bool { if contentText.isEmpty { return false } return true }
Swift
복사
이렇게 써두게 되면 isEmpty 상황일때 Post버튼이 비활성화 됩니다.
didSelectPost()
Post 버튼을 눌렀을 때 불립니다. ↔ Cancel를 눌렀을 때 호출되는 didSelectedCancel()
configurationItems()
compose View에 Configuration item를 표시해야하는 경우에 구현
override func configurationItems() -> [Any]! { return [] }
Swift
복사
Any 자리에는 SLComposeSheetConfigurationItem 타입을 넣으면 됩니다.
pushConfigurationViewController 라는 게 있는데(popConfigurationViewController도 존재) View를 push해줍니다.
override func configurationItems() -> [Any]! { let item = SLComposeSheetConfigurationItem()! item.title = "Miraclone" item.value = "Coding" item.tapHandler = { let viewController = ShareViewController() self.pushConfigurationViewController(viewController) } return [item] }
Swift
복사
요상한 모습......
share sheet에 나오는 속성들 제어하기
NSExtensionAcivationRule를 이용해서 Share하는 숫자와 어떤 타입만을 Share할 수 있는지 적용할 수 있어요.
원래는 NSExtensionAttribute는 String값으로 TRUEPREDICATE로 어떤 앱에서든 Share Extension를 통해서 내가 만든 앱을 볼 수 있어요!
하지만 제약을 걸게 되면 아무 앱에서나 볼 수 없습니다. 해당 조건에 맞는 타입이라면 Share가 가능합니다.
NSExtensionActivationSupportsImageWithMaxCount를 3으로 줬어요!
Image 타입 같은 건 3개까지만 Share가 가능한거죠.