2010-12-21 15 views
3

最新のFacebook Connect SDKを実装しようとしていますが、いくつか問題があります。何らかの理由で、FBSessionDelegateプロトコルの代理コールバックが起動されていません。私はgitのFacebookページの指示に従い、Facebookのサンプルアプリを模倣しようとしましたが運はありませんでした。私はここに夢中になるので、私は自分のコードを投稿し、誰かが私が逃したばかげた何かを見るかもしれない。FBSessionDelegateメソッドが起動しない

#import <Foundation/Foundation.h> 
#import "FBConnect.h" 

@interface FacebookWrapper : UIViewController <FBSessionDelegate, FBRequestDelegate, FBDialogDelegate>{ 
Facebook* _facebook; 
NSArray* _permissions; 
} 

@property(readonly) Facebook *facebook; 

- (void)login; 

@end 

#import "FacebookWrapper.h" 

static NSString* kAppId = @"1234455667778"; 

@implementation FacebookWrapper 

@synthesize facebook = _facebook; 

- (id)init { 
if (self = [super init]) { 
    _permissions = [[NSArray arrayWithObjects: @"read_stream", @"offline_access",nil] retain]; 
    _facebook = [[Facebook alloc] initWithAppId:kAppId]; 

} 
return self; 
} 

- (void)dealloc { 
[_facebook release]; 
[_permissions release]; 
[super dealloc]; 
} 

- (void)login { 
[_facebook authorize:_permissions delegate:self]; 
} 

- (void)fbDidLogin { 
NSLog(@"Did Log In"); 
} 

- (void)fbDidNotLogin:(BOOL)cancelled { 
NSLog(@"Failed to log in"); 
} 

- (void)fbDidLogout { 
NSLog(@"Logged Out"); 
} 

そして予想通り、私は電話で見ている動作です

FacebookWrapper *fw = [[FacebookWrapper alloc] init]; 
[fw login]; 

、別のクラスからこれをコールします。 Facebookアプリケーションがinitで起動し、権限が要求されます。電話は私のアプリをフォアグラウンドに戻しますが、FBSessionDelegateの代議員は決して解雇されません。私は、私のアプリIDを使ってFacebookのサンプルアプリでこれを試してみました。私は違いが何であるか分かりません。

答えて

7

問題を見つけました。 App Delegateでは、handleOpenURLをオーバーライドする必要があります。

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { 
    return [[facebookWrapper facebook] handleOpenURL:url]; 
} 

私はあなたがFacebookのクラスでhanleOpenURLメソッドを呼び出すことができるようにアプリのデリゲートでそれのインスタンスをする必要があります午前とあなたはラッパークラスを作成している場合。また、私のFacebookインスタンスのpublic readonlyプロパティがFacebookWrapperクラスにあるので、handlOpenURLを呼び出すことができます。

これを実行すると、アプリはFacebookアプリ内で権限を取得してからどこに戻るかを知ることができます。

+0

私はこれが古い投稿であることを認識していますが、この問題について何か覚えておけばそれが役に立ちます。 あなたは電話しますか: 'FacebookWrapper * fw = [[FacebookWrapper alloc] init]; [fw login]; ' 、ビューコントローラから、またはアプリケーションデリゲートからコントローラとアプリケーションデリゲートクラスの両方からFacebookWrapperインスタンスへの参照をどのように持つことが可能でしょうか? ありがとうございました – Teddy

+0

@Teddy Singleton! – bearMountain

3

私はあなたに非常に役立つラッパークラスを開発しました。

最初にFacebookの最新SDKをダウンロードしてください。

.hファイルに次のコードを追加します

を "FacebookHelper" という名前の1つのクラスを作成します。

#import <Foundation/Foundation.h> 
#import "FBConnect.h" 

@protocol FBApiCallDelegate; 

typedef enum FBApiCallType 
{ 
FBApiCallNone = 0, 
FBApiCallGetUserInfo = 1, 
FBApiCallGetUserFriend = 2, 
FBApiCallPostMessage = 3, 
FBApiCallPostPicture = 4, 
FBApiCallShareLink = 5, 
FBApiCallPostAll = 6, 
FBApiCallPostMessageFriendWall = 7 

} FBApiCallType; 

@interface FacebookHelper : NSObject<FBRequestDelegate, FBDialogDelegate, FBSessionDelegate> { 
Facebook *objFacebook; 
NSArray *arrPermission; 

id<FBApiCallDelegate> apiCallDelegate; 
FBApiCallType currentApiCallType; 

NSString *strMessage; 
NSString *strUrlTitle; 
NSString *strUrl; 
NSString *strCaption; 
NSString *strPictureUrl; 
UIImage *image; 
} 
@property(readonly) Facebook *objFacebook; 

@property (nonatomic, assign) id<FBApiCallDelegate> apiCallDelegate; 
@property (nonatomic, assign) FBApiCallType currentApiCallType; 

@property (nonatomic, retain) NSString *strMessage; 
@property (nonatomic, retain) NSString *strUrlTitle; 
@property (nonatomic, retain) NSString *strUrl; 
@property (nonatomic, retain) NSString *strCaption; 
@property (nonatomic, retain) NSString *strPictureUrl; 
@property (nonatomic, retain) UIImage *image; 


+ (FacebookHelper *) sharedInstance; 
- (void)releaseObjects; 

//Store Authentication 
- (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt; 
- (void)removeAuthData; 

//Public Methods 
-(BOOL)isLoggedIn; 
-(void)loginToFacebook; 
-(void)logoutFromFacebook; 

//Facebook Methods 
-(void)getUserInfo;     //Get User Info 
-(void)getUserFriends;    //Get User's Friend List 
-(void)postMessageToWall;   //Post Message to FB Wall 
-(void)postPictureToWall;   //Post Picture to FB Wall 
-(void)shareLinkOnWall;    //Share Link on FB Wall 
-(void)postAllToWall;    //Post All - Message, Link, Caption, PhotoUrl 
-(void)postMessageToFriendWall;  //Post Message to Friend Wall 


//String Methods 
- (BOOL)isEmptyString:(NSString *)strValue; 
- (NSString *) trimWhiteSpace:(NSString *)strValue; 

// Default AlertView 
-(void)showAlertView:(NSString *)pstrTitle withMessage:(NSString *)pstrMessage delegate:(id)pDelegate; 

@end 

@protocol FBApiCallDelegate <NSObject> 

@optional 

//Get User Info Delegate 
-(void)finishUserInfoResponse:(id)result; 
-(void)failedUserInfoResponse:(NSError *)error; 

//Get User's Friend List 
-(void)finishUserFriendResponse:(id)result; 
-(void)failedUserFriendResponse:(NSError *)error; 

//Post Message to FB Wall Delegate 
-(void)finishPostMessageResponse:(id)result; 
-(void)failedPostMessageResponse:(NSError *)error; 

//Post Picture to FB Wall 
-(void)finishPostPictureResponse:(id)result; 
-(void)failedPostPictureResponse:(NSError *)error; 

//Share Link on FB Wall 
-(void)finishShareLinkResponse:(id)result; 
-(void)failedShareLinkResponse:(NSError *)error; 

//Post All - Message, Link, Caption, PhotoUrl 
-(void)finishPostAllResponse:(id)result; 
-(void)failedPostAllResponse:(NSError *)error; 

//Post Message to Friend Wall Delegate 
-(void)finishPostMsgFriendWallResponse:(id)result; 
-(void)failedPostMsgFriendWallResponse:(NSError *)error; 

@end 

の.mファイルに次のコードを追加します。

#import "FacebookHelper.h" 

@implementation FacebookHelper 

@synthesize objFacebook; 
@synthesize apiCallDelegate, currentApiCallType; 
@synthesize strMessage, strUrlTitle, strUrl, strCaption, strPictureUrl, image; 

#pragma mark - 
#pragma mark Singleton Variables 
static FacebookHelper *singletonHelper = nil; 

#pragma mark - 
#pragma mark Singleton Methods 
- (id)init { 
if (!g_kFacebookAppId) { 
    NSLog(@"%@", msgFBAppIDMissing); 
    exit(1); 
    return nil; 
} 

if ((self = [super init])) { 
    arrPermission = [[NSArray arrayWithObjects: @"read_stream", @"publish_stream", @"offline_access", @"email", @"read_friendlists", @"friends_birthday",nil] retain]; 
} 

return self; 
} 
+ (FacebookHelper *)sharedInstance { 
@synchronized(self) { 
    if (singletonHelper == nil) { 
     [[self alloc] init]; // assignment not done here 
    } 
} 
return singletonHelper; 
} 
+ (id)allocWithZone:(NSZone *)zone { 
@synchronized(self) { 
    if (singletonHelper == nil) { 
     singletonHelper = [super allocWithZone:zone]; 
     // assignment and return on first allocation 
     return singletonHelper; 
    } 
} 
// on subsequent allocation attempts return nil 
return nil; 
} 
- (id)copyWithZone:(NSZone *)zone { 
return self; 
} 
- (id)retain { 
return self; 
} 
- (unsigned)retainCount { 
return UINT_MAX; // denotes an object that cannot be released 
} 
//- (void)release { 
- (void)dealloc { 
[self releaseObjects]; 

[super dealloc]; 
} 
- (id)autorelease { 
return self; 
} 
- (void)releaseObjects { 
[self.strMessage release]; 
[self.strUrlTitle release]; 
[self.strUrl release]; 
[self.strCaption release]; 
[self.strPictureUrl release]; 
[self.image release]; 

[objFacebook release]; 
objFacebook = nil; 
} 

#pragma mark - 
#pragma mark FBDelegate(FBSessionDelegate) Methods 
/** 
* Called when the user has logged in successfully. 
*/ 
- (void)fbDidLogin { 
NSLog(@"FB login OK"); 
[self storeAuthData:objFacebook.accessToken expiresAt:objFacebook.expirationDate]; 

switch(currentApiCallType) 
{ 
    case FBApiCallGetUserInfo: 
     [self getUserInfo]; 
     break; 
    case FBApiCallGetUserFriend: 
     [self getUserFriends]; 
     break; 
    case FBApiCallPostMessage: 
     [self postMessageToWall]; 
     break; 
    case FBApiCallPostPicture: 
     [self postPictureToWall]; 
     break; 
    case FBApiCallShareLink: 
     [self shareLinkOnWall]; 
     break; 
    case FBApiCallPostAll: 
     [self postAllToWall]; 
     break; 
    case FBApiCallPostMessageFriendWall: 
     [self postMessageToFriendWall]; 
     break; 

} 
} 
/** 
* Called when the user canceled the authorization dialog. 
*/ 
-(void)fbDidNotLogin:(BOOL)cancelled { 
NSLog(@"FB did not login"); 
[self removeAuthData]; 
} 
/** 
* Called when the request logout has succeeded. 
*/ 
- (void)fbDidLogout { 
NSLog(@"FB logout OK"); 
[self removeAuthData]; 
} 
-(void)fbDidExtendToken:(NSString *)accessToken expiresAt:(NSDate *)expiresAt { 
NSLog(@"token extended"); 
[self storeAuthData:accessToken expiresAt:expiresAt]; 
} 
/** 
* Called when the session has expired. 
*/ 
- (void)fbSessionInvalidated { 
[self showAlertView:msgFBSessionInvalidateTitle withMessage:msgFBSessionInvalidateMessage delegate:nil]; 
[self fbDidLogout]; 
} 

#pragma mark - 
#pragma mark FBRequestDelegate Methods 
/** 
* Called when the Facebook API request has returned a response. This callback 
* gives you access to the raw response. It's called before 
* (void)request:(FBRequest *)request didLoad:(id)result, 
* which is passed the parsed response object. 
*/ 
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response { 
NSLog(@"received response"); 
} 
/** 
* Called when a request returns and its response has been parsed into 
* an object. The resulting object may be a dictionary, an array, a string, 
* or a number, depending on the format of the API response. If you need access 
* to the raw response, use: 
* 
* (void)request:(FBRequest *)request 
*  didReceiveResponse:(NSURLResponse *)response 
*/ 
- (void)request:(FBRequest *)request didLoad:(id)result { 
NSLog(@"FB request OK"); 
switch(currentApiCallType) 
{ 
    case FBApiCallGetUserInfo: 
     if([self.apiCallDelegate respondsToSelector:@selector(finishUserInfoResponse:)]) 
      [self.apiCallDelegate finishUserInfoResponse:result]; 
     break; 

    case FBApiCallGetUserFriend: 
     if ([self.apiCallDelegate respondsToSelector:@selector(finishUserFriendResponse:)]) 
      [self.apiCallDelegate finishUserFriendResponse:result]; 
     break; 

    case FBApiCallPostMessage: 
     if ([self.apiCallDelegate respondsToSelector:@selector(finishPostMessageResponse:)]) 
      [self.apiCallDelegate finishPostMessageResponse:result]; 
     break; 

    case FBApiCallPostPicture: 
     if ([self.apiCallDelegate respondsToSelector:@selector(finishPostPictureResponse:)]) 
      [self.apiCallDelegate finishPostPictureResponse:result]; 
     break; 

    case FBApiCallShareLink: 
     if ([self.apiCallDelegate respondsToSelector:@selector(finishShareLinkResponse:)]) 
      [self.apiCallDelegate finishShareLinkResponse:result]; 
     break; 

    case FBApiCallPostAll: 
     if ([self.apiCallDelegate respondsToSelector:@selector(finishPostAllResponse:)]) 
      [self.apiCallDelegate finishPostAllResponse:result]; 
     break; 

    case FBApiCallPostMessageFriendWall: 
     if ([self.apiCallDelegate respondsToSelector:@selector(finishPostMsgFriendWallResponse:)]) 
      [self.apiCallDelegate finishPostMsgFriendWallResponse:result]; 
     break; 
} 
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 

currentApiCallType = FBApiCallNone; 
} 
/** 
* Called when an error prevents the Facebook API request from completing 
* successfully. 
*/ 
/*- (void)request:(FBRequest *)request didFailWithError:(NSError *)error { 
NSLog(@"FB error: %@", [error localizedDescription]); 
}*/ 
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error { 
NSLog(@"Err message: %@", [[error userInfo] objectForKey:@"error_msg"]); 
/*NSLog(@"Err code: %@", [error code]); 
NSLog(@"Err desc: %@", [error description]); 
NSLog(@"FB error: %@", [error localizedDescription]);*/ 

switch(currentApiCallType) 
{ 
    case FBApiCallGetUserInfo: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedUserInfoResponse:)]) 
      [self.apiCallDelegate failedUserInfoResponse:error]; 
     break; 

    case FBApiCallGetUserFriend: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedUserFriendResponse:)]) 
      [self.apiCallDelegate failedUserFriendResponse:error]; 
     break; 

    case FBApiCallPostMessage: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedPostMessageResponse:)]) 
      [self.apiCallDelegate failedPostMessageResponse:error]; 
     break; 

    case FBApiCallPostPicture: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedPostPictureResponse:)]) 
      [self.apiCallDelegate failedPostPictureResponse:error]; 
     break; 

    case FBApiCallShareLink: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedShareLinkResponse:)]) 
      [self.apiCallDelegate failedShareLinkResponse:error]; 
     break; 

    case FBApiCallPostAll: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedPostAllResponse:)]) 
      [self.apiCallDelegate failedPostAllResponse:error]; 

    case FBApiCallPostMessageFriendWall: 
     if ([self.apiCallDelegate respondsToSelector:@selector(failedPostMsgFriendWallResponse:)]) 
      [self.apiCallDelegate failedPostMsgFriendWallResponse:error]; 
     break; 
} 
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; 

currentApiCallType = FBApiCallNone; 
} 
/** 
* Called when a UIServer Dialog successfully return. 
*/ 
- (void)dialogDidComplete:(FBDialog *)dialog { 
NSLog(@"Published successfully on FB"); 
} 

#pragma mark - 
#pragma mark Store/Remove Authentication 
- (void)storeAuthData:(NSString *)accessToken expiresAt:(NSDate *)expiresAt { 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setObject:accessToken forKey:g_kFacebookAccessToken]; 
[defaults setObject:expiresAt forKey:g_kFacebookExpirationDate]; 
[defaults synchronize]; 
} 
- (void)removeAuthData{ 
// Remove saved authorization information if it exists and it is 
// ok to clear it (logout, session invalid, app unauthorized) 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults removeObjectForKey:g_kFacebookAccessToken]; 
[defaults removeObjectForKey:g_kFacebookExpirationDate]; 
[defaults synchronize]; 

/* 
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:g_kFacebookAccessToken]; 
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:g_kFacebookExpirationDate]; 
[[NSUserDefaults standardUserDefaults] synchronize];*/ 
/* 
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:g_kFacebookAccessToken]; 
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:g_kFacebookExpirationDate]; 
[[NSUserDefaults standardUserDefaults] synchronize];*/ 
} 

#pragma mark - 
#pragma mark Public Methods 
-(BOOL)isLoggedIn 
{ 
if(objFacebook == nil) 
    objFacebook = [[[Facebook alloc] initWithAppId:g_kFacebookAppId andDelegate:self] retain]; 

NSString *strAccessToken = [[NSUserDefaults standardUserDefaults] stringForKey:g_kFacebookAccessToken]; 
NSLog(@"Access Token = %@", strAccessToken); 

//if(![strAccessToken isEmptyString]) 
if(![self isEmptyString:strAccessToken]) 
{ 
    objFacebook.accessToken = [[NSUserDefaults standardUserDefaults] stringForKey:g_kFacebookAccessToken]; 
    objFacebook.expirationDate = (NSDate *) [[NSUserDefaults standardUserDefaults] objectForKey:g_kFacebookExpirationDate]; 
} 

if([objFacebook isSessionValid]) 
    return YES; 
else 
    return NO; 

return NO; 
} 
-(void)loginToFacebook 
{ 
if(![self isLoggedIn]) 
    [objFacebook authorize:arrPermission]; 
} 
-(void)logoutFromFacebook { 
[objFacebook logout:self]; 

[self removeAuthData]; 
[self releaseObjects]; 
} 

#pragma mark - 
#pragma mark Facebook Methods 
-(void)getUserInfo 
{ 
currentApiCallType = FBApiCallGetUserInfo; 
if([self isLoggedIn]) 
{ 
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"name,picture",@"fields",nil]; 
    [objFacebook requestWithGraphPath:@"me" andParams:params andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 
-(void)getUserFriends 
{ 
currentApiCallType = FBApiCallGetUserFriend; 
if([self isLoggedIn]) 
{ 
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,birthday,link,gender,last_name,first_name",@"fields",nil]; 
    [objFacebook requestWithGraphPath:@"me/friends" andParams:params andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 
-(void)postMessageToWall 
{ 
currentApiCallType = FBApiCallPostMessage; 
if([self isLoggedIn]) 
{ 
    NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease]; 
    [params setObject:@"status" forKey:@"type"]; 
    [params setObject:self.strMessage forKey:@"message"]; 
    [objFacebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 
-(void)postPictureToWall 
{ 
currentApiCallType = FBApiCallPostPicture; 
if([self isLoggedIn]) 
{ 
    NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease]; 
    [params setObject:self.image forKey:@"source"]; 
    [params setObject:self.strMessage forKey:@"message"]; 
    [objFacebook requestWithGraphPath:@"me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 
-(void)shareLinkOnWall 
{ 
currentApiCallType = FBApiCallShareLink; 
if([self isLoggedIn]) 
{ 
    NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease]; 
    [params setObject:@"link" forKey:@"type"]; 
    [params setObject:self.strUrl forKey:@"link"]; 
    [params setObject:self.strMessage forKey:@"description"]; 
    [objFacebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 
-(void)postAllToWall 
{ 
currentApiCallType = FBApiCallPostAll; 
if([self isLoggedIn]) 
{ 
    NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease]; 
    [params setObject:self.strMessage forKey:@"description"]; 
    [params setObject:self.strUrlTitle forKey:@"name"]; 
    [params setObject:self.strUrl forKey:@"link"]; 
    [params setObject:self.strCaption forKey:@"caption"]; 
    [params setObject:self.strPictureUrl forKey:@"picture"]; 
    [objFacebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 
-(void)postMessageToFriendWall 
{ 
currentApiCallType = FBApiCallPostMessageFriendWall; 
if([self isLoggedIn]) 
{ 
    NSString *strGraphPath = [NSString stringWithFormat:@"%@/feed", @"100002305497328"]; 
    //NSString *strGraphPath = [NSString stringWithFormat:@"%@/feed", @"100002560928461"]; 

    NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease]; 
    [params setObject:self.strMessage forKey:@"message"]; 
    [objFacebook requestWithGraphPath:strGraphPath andParams:params andHttpMethod:@"POST" andDelegate:self]; 
} 
else 
    [self loginToFacebook]; 
} 

#pragma mark - 
#pragma mark String Methods 
- (BOOL)isEmptyString:(NSString *)strValue 
{ 
NSString *copy; 

if (strValue == nil) 
    return (YES); 

if ([strValue isEqualToString:@""]) 
    return (YES); 

if ([strValue isEqualToString:@"(null)"]) 
    return (YES); 

copy = [[strValue copy] autorelease]; 

//if ([[copy trimWhiteSpace] isEqualToString: @""]) 
if ([[self trimWhiteSpace:copy] isEqualToString: @""]) 
    return (YES); 

return (NO); 
} /*stringIsEmpty*/ 
- (NSString *) trimWhiteSpace:(NSString *)strValue 
{ 
NSMutableString *s = [[strValue mutableCopy] autorelease]; 
CFStringTrimWhitespace ((CFMutableStringRef) s); 
return (NSString *) [[s copy] autorelease]; 
} /*trimWhiteSpace*/ 

#pragma mark - 
#pragma mark Default AlertView 
-(void)showAlertView:(NSString *)pstrTitle withMessage:(NSString *)pstrMessage delegate:(id)pDelegate 
{ 
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:pstrTitle message:pstrMessage delegate:pDelegate cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alertView show]; 
[alertView release];  
} 

@end 

それだこと。今、私たちのFacebookラッパークラスは準備が整いました。

3つのクラスを作成して組織を改善します。

FacebookGlobal.h

データの下に追加します。

#define g_kFacebookAppId  @"<Your AppID>" 
#define g_kFacebookAppSecret @"<Your Secret>" 


#define g_kPostMessage   @"<Message>" 
#define g_kPostUrlTitle   @"<Title>" 
#define g_kPostUrl    @"<Url>" 
#define g_kPostCaption   @"<Caption>" 
#define g_kPostPictureUrl  @"<Image Url>" 

FacebookKey.h

は、データの下に追加します。

#define g_kFacebookAccessToken  @"FBAccessTokenKey" 
#define g_kFacebookExpirationDate @"FBExpirationDateKey" 

FacebookMes​​sage.h

広告をデータ以下D:輸入あなたの中のファイル以下

//AppID Missing 
#define msgFBAppIDMissing @"Missing AppID" 

//Session Invalidated 
#define msgFBSessionInvalidateTitle @"Auth Exception" 
#define msgFBSessionInvalidateMessage @"Your session has expired." 

。pchファイル:

#import "FacebookGlobal.h" 
#import "FacebookKey.h" 
#import "FacebookMessage.h" 

#import "FacebookHelper.h" 

これで準備は整いました。あなたのビューコントローラで

、デリゲートの下に追加します。あなたのビューコントローラの.mファイルで

<FBApiCallDelegate> 

を、委任にもコールするメソッドの下に追加します。

:)

コーディング
- (void)viewWillAppear:(BOOL)animated { 
/* 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
[fbHelper logoutFromFacebook]; 
*/ 


//Get User Info 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
[fbHelper getUserInfo]; 


/* 
//Get User's Friend List 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
[fbHelper getUserFriends]; 
*/ 

/* 
//Post Message to FB Wall 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
fbHelper.strMessage = g_kPostMessage; 
[fbHelper postMessageToWall]; 
*/ 

/* 
//Post Picture to FB Wall 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
fbHelper.strMessage = g_kPostMessage; 
fbHelper.image = [UIImage imageNamed:@"postPicture.jpg"]; 
[fbHelper postPictureToWall]; 
*/ 

/* 
//Share Link on FB Wall 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
fbHelper.strUrl = g_kPostUrl; 
fbHelper.strMessage = g_kPostMessage; 
[fbHelper shareLinkOnWall]; 
*/ 

/* 
//Post All to FB Wall 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
fbHelper.strMessage = g_kPostMessage; 
fbHelper.strUrlTitle = g_kPostUrlTitle; 
fbHelper.strUrl = g_kPostUrl; 
fbHelper.strCaption = g_kPostCaption; 
fbHelper.strPictureUrl = g_kPostPictureUrl; 
[fbHelper postAllToWall]; 
*/ 

/* 
//Post Message to Friend Wall 
FacebookHelper *fbHelper = [FacebookHelper sharedInstance]; 
fbHelper.apiCallDelegate = self; 
fbHelper.strMessage = g_kPostMessage; 
[fbHelper postMessageToFriendWall]; 
*/ 
} 



#pragma mark - 
#pragma mark Get User Info Delegate 
-(void)finishUserInfoResponse:(id)result{ 
NSLog(@"UserInfo response successed!"); 
NSLog(@"%@", result); 

} 
-(void)failedUserInfoResponse:(NSError *)error{ 
NSLog(@"UserInfo response failed!"); 
} 

#pragma mark - 
#pragma mark Get User's Friend List 
-(void)finishUserFriendResponse:(id)result{ 
NSLog(@"User FriendList response successed!"); 
NSLog(@"%@", result); 
} 
-(void)failedUserFriendResponse:(NSError *)error{ 
NSLog(@"User FriendList response failed!"); 
} 

#pragma mark - 
#pragma mark Post Message to FB Wall Delegate 
-(void)finishPostMessageResponse:(id)result{ 
NSLog(@"Post message successed!"); 
NSLog(@"%@", result); 
} 
-(void)failedPostMessageResponse:(NSError *)error{ 
NSLog(@"Post message failed!"); 
} 

#pragma mark - 
#pragma mark Post Picture to FB Wall 
-(void)finishPostPictureResponse:(id)result{ 
NSLog(@"Post picture successed!"); 
NSLog(@"%@", result); 
} 
-(void)failedPostPictureResponse:(NSError *)error{ 
NSLog(@"Post picture failed!"); 
} 

#pragma mark - 
#pragma mark Share Link on FB Wall 
-(void)finishShareLinkResponse:(id)result{ 
NSLog(@"Share link successed!"); 
NSLog(@"%@", result); 
} 
-(void)failedShareLinkResponse:(NSError *)error{ 
NSLog(@"Share link failed!"); 
} 

#pragma mark - 
#pragma mark Post All - Message, Link, Caption, PhotoUrl 
-(void)finishPostAllResponse:(id)result{ 
NSLog(@"Post all successed!"); 
NSLog(@"%@", result); 
} 
-(void)failedPostAllResponse:(NSError *)error{ 
NSLog(@"Post all failed!"); 
} 

#pragma mark - 
#pragma mark Post Message to Friend Wall Delegate 
-(void)finishPostMsgFriendWallResponse:(id)result{ 
NSLog(@"Post message to friend wall successed!"); 
NSLog(@"%@", result); 
} 
-(void)failedPostMsgFriendWallResponse:(NSError *)error{ 
NSLog(@"Post message to friend wall failed!"); 
} 

ハッピー

お楽しみください。