Swift实现FBSDKAppInviteDialogDelegate不起作用 [英] Swift implementation of FBSDKAppInviteDialogDelegate not working

查看:209
本文介绍了Swift实现FBSDKAppInviteDialogDelegate不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的类上实现协议FBSDKAppInviteDialogDelegate,但xcode显示了一个错误,表示Type MyClass不符合协议FBSDKAppInviteDialogDelegate'



协议的定义:

  @protocol FBSDKAppInviteDialogDelegate< NSObject> 

/ *!
@abstract发送给代理,当应用程序邀请完成没有错误。
@param appInviteDialog完成的FBSDKAppInviteDialog。
@param结果对话框的结果。这可能是零或空。
* /
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results;

/ *!
@abstract应用程序邀请遇到错误时发送给代理。
@param appInviteDialog完成的FBSDKAppInviteDialog。
@param错误错误。
* /
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError :((NSError *)错误;

@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方法的实现: / p>

  // FBSDKAppInviteDialogDelegate的功能
func appInviteDialog(appInviteDialog:FBSDKAppInviteDialog !, didCompleteWithResults results:NSDictionary!){
//我的代码
}
// FBSDKAppInviteDialogDelegate的功能
func appInviteDialog(appInviteDialog:FBSDKAppInviteDialog !, didFailWithError error:NSError!){
//我的代码在这里
}

邀请对话框工作。但是没有协议,我无法获得结果。



我在这里缺少什么?

解决方案

问题在于NSDictionary。以下内容适用于我:

  func appInviteDialog(appInviteDialog:FBSDKAppInviteDialog !, didCompleteWithResults results:[NSObject:AnyObject]!){ 
println(完全邀请没有错误)
}

func appInviteDialog(appInviteDialog:FBSDKAppInviteDialog !, didFailWithError error:NSError!){
println(邀请\(错误))
}


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?

解决方案

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

这篇关于Swift实现FBSDKAppInviteDialogDelegate不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆