不兼容的指针类型将类发送到类型为id fbsessiondelegate的参数

时间:2012-09-19 19:27:27

标签: iphone ios facebook sharekit

将Sharekit组添加到我的项目中并获得如此多的编译警告。

在这里它是一个静态实例,并且在静态方法中传递self参数是不正确的,因为静态方法中没有此对象的特定实例。我怎么能解决这个问题。

 + (void)logout
{
FBSession *fbSession; 

if(!SHKFacebookUseSessionProxy){
    fbSession = [FBSession sessionForApplication:SHKFacebookKey
                                             secret:SHKFacebookSecret
                                           delegate:self];

}else {
    fbSession = [FBSession sessionForApplication:SHKFacebookKey
                                    getSessionProxy:SHKFacebookSessionProxyURL
                                          delegate:self];
                  //delegate:[self sharedSomeProtocolDelegate]];
}

[fbSession logout];
}

任何人请。

由于

2 个答案:

答案 0 :(得分:1)

执行符合FBSessionDelegate协议的SocialManager对象。实例化它并在代码中代替self参数。例如:

SocialManager.h:

 @interface SocialManager : NSObject <FBSessionDelegate>
- (id) init;
/**
 * Called when the user successfully logged in.
 */
- (void)fbDidLogin;

/**
 * Called when the user dismissed the dialog without logging in.
 */
- (void)fbDidNotLogin:(BOOL)cancelled;

/**
 * Called when the user logged out.
 */
- (void)fbDidLogout;
@end

SocialManager.m:

-(id) init
{
  self = [super init];
  return self;
}
- (void)fbDidLogin;
{
}
- (void)fbDidNotLogin:(BOOL)cancelled;
{
}
- (void)fbDidLogout
{
}

并在您的代码中:

 + (void)logout
{
FBSession *fbSession;
SocialManager* socialManager = [[SocialManager alloc] init];

if(!SHKFacebookUseSessionProxy){
    fbSession = [FBSession sessionForApplication:SHKFacebookKey
                                             secret:SHKFacebookSecret
                                           delegate:socialManager];

}else {
    fbSession = [FBSession sessionForApplication:SHKFacebookKey
                                    getSessionProxy:SHKFacebookSessionProxyURL
                                          delegate:socialManager];
                  //delegate:[self sharedSomeProtocolDelegate]];
}

[fbSession logout];
}

这是一个简单的示例,但您必须在代码中实现自己的委托。只需添加到您的对象(可能是viewController)中的方法,并将此对象设置为FBsession的委托。

答案 1 :(得分:1)

使用静态类时,您可以在这种情况下手动获取警告:

...
delegate:(id<FBSessionDelegate>)self];