【问题标题】:facebook integration in iphone with Facebook sdk for ios5 and 6iphone 中的 facebook 与 ios5 和 6 的 Facebook sdk 集成
【发布时间】:2012-12-24 12:13:14
【问题描述】:

我已经使用 FAcebook sdk 3.0 来集成 facebook。我已经使用示例代码“HelloFacebookSample” 发布状态。 我的 AppId 更改了 Info.plist 文件。 我遇到了显示 armv7s、armv7 架构问题的问题。我什至通过“仅构建活动架构”来解决这个问题。

我有显示 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 和 6 中。

【问题讨论】:

  • 对于 iOS6,有内置的 Facebook 集成功能...
  • 您肯定需要发布更多代码才能让我们为您提供帮助。
  • @jinal 嘿,亲爱的 vishal 说得对。在这里你可以在 ios5 中获得像 twitter 这样的 facebook 框架,你能接受我给你的有用的答案吗??
  • 但是如果想在 ios5 中运行应用程序呢?那不行吗?

标签: iphone facebook ios5 ios6


【解决方案1】:

【讨论】:

    【解决方案2】:
        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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-09
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多