【问题标题】:Swift implementation of FBSDKAppInviteDialogDelegate not workingFBSDKAppInviteDialogDelegate 的 Swift 实现不起作用
【发布时间】:2015-04-28 19:32:31
【问题描述】:

我正在尝试在我的班级上实现协议 FBSDKAppInviteDialogDelegate,但 xcode 向我显示一个错误,提示“Type MyClass 不符合协议'FBSDKAppInviteDialogDelegate'”

协议定义:

@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

我的代码:

我的类的定义

class MyClasse: UITableViewController, FBSDKAppInviteDialogDelegate

调用邀请对话框:

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

procol方法的实现:

//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
}

邀请对话框有效。但是没有协议我无法得到结果。

我在这里缺少什么?

【问题讨论】:

  • 看起来类似于this。我认为这与您的协议方法的签名有关。

标签: ios facebook swift facebook-ios-sdk


【解决方案1】:

问题在于 NSDictionary。以下对我有用:

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

【讨论】:

    猜你喜欢
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多