【Swift】코피페로 할 수 있다! SDK를 사용하지 않고 SNS (Twitter/Facebook/Line/Mail)로 공유하는 방법 요약
라이브러리 설치가 없으므로 copipe로 할 수 있습니다.
하지만 평소에는 UIActivity를 사용하고 있다고 생각하지만 ...
완성형




UIActivity는 이것

Social 가져오기
import UIKit
import Social
SNS를 열거해 둔다
enum SNS: Int {
case line = 1
case twitter = 2
case facebook = 3
case mail = 4
}
공유하기
SLComposeViewController
를 사용하고 있습니다. private func openURL(url: URL?) {
guard let url = url else { return }
if UIApplication.shared.canOpenURL(url) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
private func shareSNS(sns: SNS) {
let shareURL = "https://hogehogehogeho.com"
switch sns {
case .facebook:
guard let composeViewController: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook) else { return }
composeViewController.setInitialText(shareURL)
self.present(composeViewController, animated: true, completion: nil)
case .line:
guard let scheme: String = "line://msg/text/\(shareURL)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return }
self.openURL(url: URL(string: scheme))
case .mail:
guard let string = "mailto:[email protected]?body=\(shareURL)".addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else { return }
self.openURL(url: URL(string: string))
case .twitter:
guard let vc = SLComposeViewController(forServiceType:SLServiceTypeTwitter) else { return }
vc.setInitialText(shareURL)
self.present(vc, animated: true, completion: nil)
}
}
요약
UIActivityViewController
를 사용하지 않고 공유를 할 수 있었습니다 Reference
이 문제에 관하여(【Swift】코피페로 할 수 있다! SDK를 사용하지 않고 SNS (Twitter/Facebook/Line/Mail)로 공유하는 방법 요약), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/okamu_/items/11672f37bad8bbfeb4c2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)