Swift implementation of FBSDKAppInviteDialogDelegate not working

旧街凉风 提交于 2019-12-23 20:10:32

问题


I'm trying to implement the protocol FBSDKAppInviteDialogDelegate on my class but the xcode show me a erro that says "Type MyClass does not conform to protocol 'FBSDKAppInviteDialogDelegate'"

Definition of protocol:

@protocol FBSDKAppInviteDialogDelegate <NSObject>

/*!
@abstract Sent to the delegate when the app invite completes without error.
@param appInviteDialog The FBSDKAppInviteDialog that completed.
@param results The results from the dialog.  This may be nil or empty.
*/
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results;

/*!
@abstract Sent to the delegate when the app invite encounters an error.
@param appInviteDialog The FBSDKAppInviteDialog that completed.
@param error The error.
*/
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error;

@end

My code:

The definition of my class

class MyClasse: UITableViewController, FBSDKAppInviteDialogDelegate

To call the invite dialog:

var inviteDialog:FBSDKAppInviteDialog = FBSDKAppInviteDialog()
if(inviteDialog.canShow()){
    let appLinkUrl:NSURL = NSURL(string: "http://mylink.com")!
    let previewImageUrl:NSURL = NSURL(string: "http://mylink.com/image.png")!

    var inviteContent:FBSDKAppInviteContent = FBSDKAppInviteContent(appLinkURL: appLinkUrl)
    inviteContent.previewImageURL = previewImageUrl

    inviteDialog.content = inviteContent
    inviteDialog.delegate = self
    inviteDialog.show()
}

The implementation of procol methods:

//function of FBSDKAppInviteDialogDelegate
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: NSDictionary!){
    // my code here
}
//function of FBSDKAppInviteDialogDelegate
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!){
    // my code here
}

The invitation dialog works. But without the protocol i cant get the results.

What i'm missing here?


回答1:


The issue is with NSDictionary. The following is working for me:

func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) {
    println("Complete invite without error")
}

func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) {
    println("Error in invite \(error)")
}


来源:https://stackoverflow.com/questions/29928298/swift-implementation-of-fbsdkappinvitedialogdelegate-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!