簡體   English   中英

使用iOS5和6的Facebook SDK將iPhone中的Facebook集成

[英]facebook integration in iphone with Facebook sdk for ios5 and 6

我已經使用FAcebook sdk 3.0集成了facebook。我已經使用示例代碼“ HelloFacebookSample”來發布狀態。 我的AppId已更改Info.plist文件。 我遇到了顯示armv7s,armv7體系結構問題的問題。我什至通過向YE“僅構建活動體系結構”來解決該問題。

我有顯示用於Facebook登錄/注銷按鈕的代碼

#import "HFViewController.h"

#import "AppDelegate.h"
 #import <CoreLocation/CoreLocation.h>


 @interface HFViewController () <FBLoginViewDelegate>


 @property (strong, nonatomic) IBOutlet UIButton *buttonPostStatus;

 @property (strong, nonatomic) id<FBGraphUser> loggedInUser;

 - (IBAction)postStatusUpdateClick:(UIButton *)sender;


 - (void)showAlert:(NSString *)message
       result:(id)result
        error:(NSError *)error;


 @end

 @implementation HFViewController
 @synthesize shareStringFb;
 @synthesize buttonPostStatus = _buttonPostStatus;

 @synthesize loggedInUser = _loggedInUser;


 - (void)viewDidLoad {    
[super viewDidLoad];

// Create Login View so that the app will be granted "status_update" permission.
self.buttonPostStatus.enabled = YES;

FBLoginView *loginview = [[FBLoginView alloc] init];

loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;

[self.view addSubview:loginview];

[loginview sizeToFit];
statusText.text=self.shareStringFb;
{
    // if the session is closed, then we open it here, and establish a handler for state changes
}

}

 -(IBAction)backClick:(id)sender
 {
[self.view removeFromSuperview];

 }

 - (void)viewDidUnload {

self.buttonPostStatus = nil;

self.loggedInUser = nil;

[super viewDidUnload];
 }



 - (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
// first get the buttons set for login mode

  self.buttonPostStatus.enabled = YES;

 }

 - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user {
// here we use helper properties of FBGraphUser to dot-through to first_name and
// id properties of the json response from the server; alternatively we could use
// NSDictionary methods such as objectForKey to get values from the my json object

 self.loggedInUser = user;
 }

 - (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {

   self.buttonPostStatus.enabled = NO;

  }

//發布狀態更新按鈕處理程序-(IBAction)postStatusUpdateClick:(UIButton *)sender {

// Post a status update to the user's feed via the Graph API, and display an alert view 
// with the results or an error.

 NSString *message = [NSString stringWithFormat:@"Updating %@'s status at %@", 
                     self.loggedInUser.first_name, [NSDate date]];

 [FBRequestConnection startForPostStatusUpdate:self.shareStringFb
                            completionHandler:^(FBRequestConnection *connection, id          result, NSError *error) {

                                [self showAlert:message result:result error:error];
                                self.buttonPostStatus.enabled = YES;
                            }];

self.buttonPostStatus.enabled = NO;       

}

//發布照片按鈕處理程序

它在模擬器中顯示一個帶有登錄/注銷的按鈕,但是當我在設備中進行測試時,它不顯示該按鈕。

請問誰能告訴我問題是什么?為什么不顯示呢?還有其他方法可以將Fb集成到ios 5和ios 6中嗎?

    ViewController.h

    #import <FacebookSDK/FacebookSDK.h>

    {
     NSDictionary *dictionary;
        NSString *user_email;
        NSString *accessTokan;


        NSMutableDictionary *fb_dict;
    }


- (IBAction)btn_loginwithfacebook:(id)sender;
{

    if (!FBSession.activeSession.isOpen)
    {
        // if the session is closed, then we open it here, and establish a handler for state changes

        [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
         {
             if (error)
             {
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                 [alertView show];
             }
             else if(session.isOpen)
             {
                 [self btn_loginwithfacebook:sender];
             }

         }];

        return;
    }


    [FBRequestConnection startWithGraphPath:@"me" parameters:[NSDictionary dictionaryWithObject:@"picture,id,birthday,email,name,gender,username" forKey:@"fields"] HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
     {
         if (!error)
         {
             if ([result isKindOfClass:[NSDictionary class]])
             {
                 //NSDictionary *dictionary;
                 if([result objectForKey:@"data"])
                     dictionary = (NSDictionary *)[(NSArray *)[result objectForKey:@"data"] objectAtIndex:0];
                 else
                     dictionary = (NSDictionary *)result;
                 //NSLog(@"dictionary : %@",dictionary);



                 user_email = [dictionary objectForKey:@"email"];
                 [dictionary retain];
                 //NSLog(@"%@",user_email);//
             }
         }
     }];
    accessTokan = [[[FBSession activeSession] accessTokenData] accessToken];
    //NSLog(@"%@",accessTokan);

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",accessTokan]]];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    NSError *error;
    NSURLResponse *response;
    NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

    //NSLog(@"%@",str);
    fb_dict = [str JSONValue];
    [str release];}

FacebookAppID :: 370370396320150 URL類型項目0 URL方案項目0 :: fb370546396320150

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM