我正在测试一个iPhone设备,用户已登录Facebook应用。
在do, catch
块中,出现错误error is message: The operation couldn’t be completed. (FacebookShare.ShareError error 0.) on line 895 in /Users/bogdanbarbulescu/Desktop/myStreet.com/myStreet.com/MessagesViewController.swift.
我在github上发现了另一个建议:
let content = FBSDKShareLinkContent()
content.contentURL = URL(string: "https://developers.facebook.com")
FBSDKShareDialog.show(from: self, with: content, delegate: self)
但是,我收到错误Use of unresolved identifier 'FBSDKShareLinkContent'
。如果单击FBSDKShareLinkContent()
并跳到定义,我确实会进入FBSDKSharingContent.h
我在这里做什么错了?
import UIKit
import FacebookShare
import FacebookCore
import FacebookLogin
class MessagesVC {
func invitePeopleTapped() {
let alertController = UIAlertController(title: "Some title", message: "", preferredStyle: .actionSheet)
let shareOnFacebook = UIAlertAction(title: "Share on Facebook", style: .default) { _ in
let linkContent = LinkShareContent(url: URL(string: "https://www.google.com")!, quote: "Discover & Talk ")
let shareDialog = ShareDialog(content: linkContent)
shareDialog.mode = .native
shareDialog.failsOnInvalidData = true
shareDialog.completion = { result in
print("the result is \(result)")
}
do {
try shareDialog.show()
} catch {
printsNow(message: error.localizedDescription)
}
}
alertController.addAction(shareOnFacebook)
self.present(alertController, animated: true, completion: nil)
} //end invitePeopleTapped
} //end class
Using Bolts (1.9.0)
Using FBSDKCoreKit (4.38.0)
Using FBSDKLoginKit (4.38.0)
Using FBSDKMessengerShareKit (1.3.2)
Using FBSDKShareKit (4.38.0)
Using FacebookCore (0.5.0)
Using FacebookLogin (0.5.0)
Using FacebookShare (0.5.0)
Using Firebase (5.11.0)
Using GTMSessionFetcher (1.2.0)
Using GeoFire (3.0.0)
Using GoogleAppMeasurement (5.3.0)
Using GoogleUtilities (5.3.4)
Using Protobuf (3.6.1)
Using leveldb-library (1.20)
Using nanopb (0.3.901)
Using pop (1.0.10)
Full trace trace
2018-11-11 09:38:12.238951 + 0000 myStreet.com [6129:1364819] [核心] SLComposeViewController isAvailableForServiceType com.apple.social.facebook 2018-11-11 09:38:12.257468 + 0000 myStreet.com [6129:1364819] [core] SLComposeViewController isAvailableForServiceType获得了serviceType com.apple.social.facebook isAvailable 0 2018-11-11 09:38:12.295729 + 0000 myStreet.com [6129:1365297] [核心] SLComposeViewController _shareExtensionWithIdentifier:连续发现块获得了扩展名( “ {id = com.apple.share.SinaWeibo.post}”, “ {id = com.apple.share.TencentWeibo.post}”, “ {id = com.apple.share.Facebook.post}”, “ {id = com.apple.share.Vimeo.post}”, “ {id = com.apple.Music.MediaSocialShareService}”, “ {id = com.apple.mobileslideshow.StreamShareService}”, “ {id = com.apple.Health.HealthShareExtension}”, “ {id = com.apple.reminders.RemindersEditorExtension}”, “ {id = com.apple.share.Flickr.post}”, “ {id = com.apple.mobilenotes.SharingExtension}”, “ {id = com.apple.share.Twitter.post}”, “ {{= net.whatsapp.WhatsApp.ShareExtension}”)错误(空)2018-11-11 09:38:12.296845 + 0000 myStreet.com [6129:1365297] [核心] SLComposeViewController _shareExtensionWithIdentifier:连续 发现块确实更新了_identifierToShareExtensionMap { “;” com.apple.Health.HealthShareExtension“ =” {id = com.apple.Health.HealthShareExtension}“; “;” com.apple.Music.MediaSocialShareService“ =” {id = com.apple.Music.MediaSocialShareService}“; “;” com.apple.mobilenotes.SharingExtension“ =” {id = com.apple.mobilenotes.SharingExtension}“; “;” com.apple.mobileslideshow.StreamShareService“ =” {id = com.apple.mobileslideshow.StreamShareService}“; “;” com.apple.reminders.RemindersEditorExtension“ =” {id = com.apple.reminders.RemindersEditorExtension}“; “” com.apple.share.Facebook.post“ =” {id = com.apple.share.Facebook.post}“; “;” com.apple.share.Flickr.post“ =” {id = com.apple.share.Flickr.post}“; “ com.apple.share.SinaWeibo.post” =“ {id = com.apple.share.Facebook.post} extensionIdentifer com.apple.share.Facebook.post 2018-11-11 09:38:12.298926 + 0000 myStreet.com [6129:1364819] [核心] SLComposeViewController isAvailableForServiceType的YES返回 覆盖的extensionIdentifier com.apple.share.Facebook.post 2018-11-11 09:38:12.298988 + 0000 myStreet.com [6129:1364819] [核心] SLComposeViewController isAvailableForServiceType com.apple.social.facebook返回1错误是消息:操作 无法完成。行895(FacebookShare.ShareError错误0.) 在 /Users/bogdanbarbulescu/Desktop/myStreet.com/myStreet.com/MessagesViewController.swift。
答案 0 :(得分:1)
您缺少图书馆
import FBSDKShareKit
此代码正常工作
let content = FBSDKShareLinkContent()
content.contentURL = URL(string: "https://developers.facebook.com")
FBSDKShareDialog.show(from: self, with: content, delegate: self)