swift - Facebook 分享对话框失败 - 操作无法迅速完成
问题描述
我正在 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
,“{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}”、“{id = 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。1364819] [核心] SLComposeViewController isAvailableForServiceType 为覆盖的 extensionIdentifier com.apple.share.Facebook.post 返回 YES 2018-11-11 09:38:12.298988+0000 myStreet.com[6129:1364819] [核心] SLComposeViewController isAvailableForServiceType com.apple. social.facebook 返回 1 错误是消息:操作无法完成。(FacebookShare.ShareError 错误 0。)在 /Users/bogdanbarbulescu/Desktop/myStreet.com/myStreet.com/MessagesViewController.swift 中的第 895 行。
解决方案
你想念图书馆
import FBSDKShareKit
让这段代码工作
let content = FBSDKShareLinkContent()
content.contentURL = URL(string: "https://developers.facebook.com")
FBSDKShareDialog.show(from: self, with: content, delegate: self)
推荐阅读
- google-cloud-platform - 带有 GCP 模块的 Terraform
- progressive-web-apps - 使用 Angular PWA 时地图函数语法已更改
- react-native - expo 无线更新是否适用于裸工作流程?
- sql - SQL Server 中的动态/参数化存储过程
- awk - 匹配字符串模式 - 通过 awk-gsub 替换为另一个模式
- r - ggraph 节点标签大小:要么大要么非常小 - 没有中间?
- c# - 通过内部 API 或 Db 上下文查询 Hangfire?
- typescript - 如何“重建”CDK 入口点
- node.js - NodeJS:如何在从文件解析之前读取和修改缓冲区数据?
- javascript - 使用 *ngFor 动态构建手风琴