gpt4 book ai didi

swift - 从 facebook-ios-sdk 切换到 facebook-swift-sdk,在新代码中使用 FBSDKAppInviteDialogDelegate

转载 作者:行者123 更新时间:2023-11-30 12:55:00 25 4
gpt4 key购买 nike

我正在从 Facebook iOS SDK 切换到 Facebook Swift SDK。

我想收到应用邀请结果的通知。这是我在旧代码中的内容:

extension VolumesListViewController: FBSDKAppInviteDialogDelegate {

public func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: Error!) {
...
}


func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [AnyHashable: Any]!) {
...
}
}

看来在Swift SDK中,这个DialogDelegate被封装到框架中,并没有开放实现:

所以,这是 SDKDelegate:

extension AppInvite {
internal class SDKDelegate: NSObject, FBSDKAppInviteDialogDelegate {
internal var completion: ((Result) -> Void)?

func setupAsDelegateFor(_ dialog: FBSDKAppInviteDialog) {
// We need for the connection to retain us,
// so we can stick around and keep calling into handlers,
// as long as the connection is alive/sending messages.
objc_setAssociatedObject(dialog, Unmanaged.passUnretained(self).toOpaque(), self, .OBJC_ASSOCIATION_RETAIN)
dialog.delegate = self
}

func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog?, didCompleteWithResults results: [AnyHashable: Any]?) {
completion?(.success(results?.keyValueFlatMap { ($0 as? String, $1 as? String) } ?? [:]))
}

func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog?, didFailWithError error: Error) {
completion?(.failed(error))
}
}
}

如何在不使用旧框架的情况下通过通知实现相同的效果?

我的理由是这样的:

The frameworks for the Facebook SDK in Swift are organized in the same way as the Facebook SDK for iOS . They also depend upon the Facebook SDK for iOS, although this may change at some point in the future.

最佳答案

因此,为了让一切变得清晰,我只需在 SO 上发布一个问题即可:

这就是我发现的:我可以使用 AppInvite.Dialog.show(from:invite:) 的尾随闭包来从对话框获取反馈:

let appInvite = AppInvite(appLink: URL(string: "http://eggheadgames.com/cryptograms")!)
do {
try AppInvite.Dialog.show(from: self, invite: appInvite) { result in
switch result {
case .success(_):
Logger.logUIEvent("InviteFriend", label: "called")
case .failed(_):
Logger.logUIEvent("InviteFriend", label: "unavailable")
}
}
} catch _ {
Logger.logUIEvent("InviteFriend", label: "unavailable")
}

关于swift - 从 facebook-ios-sdk 切换到 facebook-swift-sdk,在新代码中使用 FBSDKAppInviteDialogDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40520543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com