Facebook在iphone5和6上与Facebook sdk集成 [英] facebook integration in iphone with Facebook sdk for ios5 and 6

查看:136
本文介绍了Facebook在iphone5和6上与Facebook sdk集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FAcebook sdk 3.0来整合facebook。我使用示例代码HelloFacebookSample
来发布状态。
我在我的AppId中更改了Info.plist文件。
我有问题,显示armv7s,armv7架构问题。我甚至通过Build Active Architecture解决了这个问题。

i have use FAcebook sdk 3.0 to integrate facebook.I have use sample code "HelloFacebookSample" to post status. I have change in Info.plist file with my AppId. I have problem that show armv7s,armv7 architecture problem.I even solve out that by "Build Active Architecture Only "to YEs.

我有代码显示用于登录/注销facebook的按钮

I have code that show button for login/logout for 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 Status Update button handler - (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;       

}

//发布照片按钮处理程序

// Post Photo button handler

它在模拟器中显示一个带登录/注销的按钮但是当我在设备中测试时它没有显示该按钮。

it show one button with login/logout in simulator but when i test in device it doesn't show that button.

请问任何人可以告诉我什么是问题?为什么没有显示?是否还有其他方法可以在ios 5和6中集成Fb。

Please any one can tell me what is problem?Why it not show that?Is there any other way to integrate Fb in ios 5 and 6 both.

推荐答案

    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 :: 370546396320150
网址类型
项目0
URL计划
项目0 :: fb370546396320150

FacebookAppID ::370546396320150 URL types Item 0 URL Schemes Item 0 ::fb370546396320150

这篇关于Facebook在iphone5和6上与Facebook sdk集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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