我想知道什么可能出错.
谢谢!
解决方法 以下是供您参考的示例代码.在您的主视图中:func safariVIEwController(controler: SFSafariVIEwController,activityItemsForURL: NSURL,Title: String?) -> [UIActivity] { //global variable for the url to be shared webPageUrl = activityItemsForURL.absoluteString //global variable for the Title to be shared webPageTitle = Title! let wcActivity = WeChatActivity() let wcMoment = WeChatMoment() return [wcActivity,wcMoment]}
定制活动1
import UIKitclass WeChatActivity : UIActivity{ overrIDe init() { self.text = "" } var text:String? overrIDe func activityType()-> String { return "WeChat" } overrIDe func activityImage()-> UIImage? { return UIImage(named: "WeChat")! } overrIDe func activityTitle() -> String { return "微信好友" } overrIDe class func activitycategory() -> UIActivitycategory{ return UIActivitycategory.Action //you can change to .Share and it'll appear in the share line } func getURLFromMessage(message:String)-> NSURL { var url = "whatsapp://" if (message != "") { url = "\(url)send?text=\(message)" } return NSURL(string: url)! } overrIDe func canPerformWithActivityItems(activityItems: [AnyObject]) -> Bool { return true; } overrIDe func performActivity() { sharetoWeChat("ftcweixin://?url=\(webPageUrl)&Title=\(webPageTitle)&description=\(webPageDescription)&img=\(webPageImageIcon)&to=chat") }}
自定义活动2:
import UIKitclass WeChatMoment : UIActivity{ overrIDe init() { self.text = "" } var text:String? overrIDe func activityType()-> String { return "WeChatMoment" } overrIDe func activityImage()-> UIImage? { return UIImage(named: "Moment")! } overrIDe func activityTitle() -> String { return "微信朋友圈" } overrIDe class func activitycategory() -> UIActivitycategory{ return UIActivitycategory.Action } func getURLFromMessage(message:String)-> NSURL { var url = "whatsapp://" if (message != "") { url = "\(url)send?text=\(message)" } return NSURL(string: url)! } overrIDe func canPerformWithActivityItems(activityItems: [AnyObject]) -> Bool { return true; } overrIDe func performActivity() { sharetoWeChat("ftcweixin://?url=\(webPageUrl)&Title=\(webPageTitle)&description=\(webPageDescription)&img=\(webPageImageIcon)&to=moment") }}
您将能够在 *** 作表的 *** 作行中看到两个新图标.您也可以将其更改为显示在共享行中,如代码中所述.
最后一点,微信在Safari VIEw上共享存在陷阱,因为微信不符合Safari的共享标准.您可以点击微信共享图标,微信即可分享.但是你只能在Safari VIEw的页面中获取页面标题和URL,而不像WKWebVIEw那样你可以使用evaluateJavaScript获取所有内容.因此,您需要从其他地方获取共享图像和描述(以便与朋友分享).
@H_502_41@ 总结以上是内存溢出为你收集整理的ios – SFSafariViewController:如何提供自定义活动?全部内容,希望文章能够帮你解决ios – SFSafariViewController:如何提供自定义活动?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)