gpt4 book ai didi

ios - FBSDKAppInviteDialogDelegate 的 Swift 实现不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 22:22:46 27 4
gpt4 key购买 nike

我正在尝试在我的类上实现协议(protocol) FBSDKAppInviteDialogDelegate,但 xcode 向我显示一个错误,提示“Type MyClass does not conform to protocol 'FBSDKAppInviteDialogDelegate'”

协议(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

我的代码:

我类(class)的定义

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

协议(protocol)方法的实现:

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

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

我在这里缺少什么?

最佳答案

问题出在 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)")
}

关于ios - FBSDKAppInviteDialogDelegate 的 Swift 实现不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29928298/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com