2016-11-10 53 views
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,儘管這可能會在未來某個時候發生變化。

回答

0

所以,對什麼事都變得清楚,我只是張貼在SO一個問題:

這是我發現:我可以使用封閉落後的AppInvite.Dialog.show(來自:邀請:)有反饋從對話框:

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") 
} 
相關問題