2012-09-19 54 views
2

將Sharekit組添加到我的項目中,並獲得許多已編譯的警告。不兼容的指針類型將類發送到類型爲id的參數fbsessiondelegate

在此它是一個靜態實例,並在靜態方法中傳遞自參數是不正確的,因爲在靜態方法中沒有此對象的特定實例。我如何解決這個問題。

+ (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]; 
} 

任何人都請。

由於

+0

忽略警告。 (在這種情況下) – 2012-09-19 19:28:54

+0

你說你有一個靜態實例 - 你的意思是有一個靜態變量,它有一個指向你的類的實例的指針?如果是這樣,你可以通過這個變量而不是'self'嗎? –

回答

1

執行這符合FBSessionDelegate協議的SocialManager對象。實例化它,並在您的代碼中給出而不是自己的參數。例如:

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可能)methonds在協議中,並將此對象設置爲FBsession的委託。

+0

有沒有比這個更容易的解決方案。 – user1452248

+0

如果我使用零而不是自我。我用它,它解決了這個問題,但我不知道在這種情況下是否可行。 – user1452248

+0

你可以試試把零。沒有什麼事情會發生,因爲協議中沒有「必需」的方法 –

1

當使用靜態類的工作,你可以手動得到在這種情況下警告坐:

... 
delegate:(id<FBSessionDelegate>)self]; 
相關問題