0
我正在從Facebook iOS SDK切換到Facebook Swift SDK。從facebook-ios-sdk切換到facebook-swift-sdk,在新代碼中使用FBSDKAppInviteDialogDelegate
我希望收到應用邀請結果的通知。這是我在舊代碼:
extension VolumesListViewController: FBSDKAppInviteDialogDelegate {
public func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: Error!) {
...
}
func appInviteDialog(_ appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [AnyHashable: Any]!) {
...
}
}
看來,在斯威夫特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))
}
}
}
如何在不使用舊框架的情況下實現與通知相同的功能?
我的理由是這樣的:
爲Facebook SDK斯威夫特的框架以同樣的方式作爲Facebook的SDK適用於iOS的組織方式。他們也依賴Facebook的iOS SDK,儘管這可能會在未來某個時候發生變化。