swift中SLComposeViewController类实现的分享

SLComposeViewController 是在ios6开始推出的,可以实现部分社交平台的分享的。
具体的分享平台有如下这些:

SLServiceTypeTwitter  //twitter
SLServiceTypeFacebook  //facebook
SLServiceTypeSinaWeibo   //新浪微博
SLServiceTypeTencentWeibo  //腾讯微博
SLServiceTypeLinkedIn    //领英

具体的实现代码也比较简单
eg:

let image:UIImage = UIImage.init(named: "timg-2.jpeg")!
let url:URL = URL.init(string: "http://www.googel.es")!
    
let shareViewController = SLComposeViewController.init(forServiceType:SLServiceTypeSinaWeibo)
shareViewController?.add(image)
shareViewController?.add(url)
shareViewController?.setInitialText("ni hao ma ")
    
let completionHandler = {(result:SLComposeViewControllerResult)->() in
    shareViewController?.dismiss(animated: true, completion: nil)
    switch result {
    case SLComposeViewControllerResult.cancelled:
        print("User canceled")
    case SLComposeViewControllerResult.done:
        print("User done")
    }
    
}
shareViewController?.completionHandler = completionHandler
self.present(shareViewController!, animated: true, completion:nil)

你可能感兴趣的:(swift中SLComposeViewController类实现的分享)