Twitter分享

分享方式1:需要判断是否安装客户度 

ifSLComposeViewController.isAvailable(forServiceType:SLServiceTypeTwitter){

letsocialComposer =SLComposeViewController.init(forServiceType:SLServiceTypeTwitter)

socialComposer?.add(url)

socialComposer?.completionHandler= {(result)in

lettoast =ToastView()

switch(result) {

case.cancelled:

toast.showToast(text:"分享失败", pos:.Mid)

case.done:

toast.showToast(text:"分享成功", pos: .Mid)

}

}

self.present(socialComposer!, animated:true, completion:nil)


}else{

lettoast =ToastView()

toast.showToast(text:"请安装twitter客户端", pos: .Mid)

}



分享方式2:不需要判断客户端,但是需要导入twiier Sdk

letcomposer =TWTRComposer()

composer.setText(url.absoluteString)

composer.show(from:self.navigationController!) { (result)in

if(result == .done) {

print("Successfully composed Tweet")

}else{

print("Cancelled composing")

}

}

你可能感兴趣的:(Twitter分享)