2016-11-10 4 views
0

Ich wechsle von Facebook iOS SDK zu Facebook Swift SDK.Wechsel von Facebook-ios-sdk zu facebook-swift-sdk, Verwendung von FBSDKAppInviteDialogDelegate im neuen Code

Ich möchte über die Ergebnisse der App Einladung informiert werden. Dies ist, was ich in den alten Code haben:

extension VolumesListViewController: FBSDKAppInviteDialogDelegate { 

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


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

Es scheint, dass in Swift SDK, das DialogDelegate in den Rahmen verkapselt ist und nicht für die Umsetzung geöffnet:

Also, das ist die 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)) 
     } 
    } 
} 

Wie erreichen Sie das gleiche mit Benachrichtigungen, ohne das alte Framework zu verwenden?

Mein Grund ist dieser:

Die Rahmenbedingungen für die Facebook-SDK in Swift sind in der gleichen Weise wie das Facebook-SDK für iOS organisiert. Sie hängen auch vom Facebook SDK für iOS ab, obwohl sich das irgendwann in der Zukunft ändern könnte.

Antwort

0

Also, alles klar zu werden, muss ich nur noch eine Frage stellen auf SO:

Dies ist, was ich gefunden habe: Ich benutze kann Verschluss für die AppInvite.Dialog.show Hinter (aus: einladen :) um Feedback vom Dialog zu haben:

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") 
}