【问题标题】:Link to User's Facebook Wall From iOS App从 iOS 应用程序链接到用户的 Facebook 墙
【发布时间】:2015-03-07 15:12:11
【问题描述】:

一直在寻找指导,但我在这里和网络上找到的大部分内容是“如何从 iOS 应用程序发布到 Facebook”。我的问题不同。

我有一个有多个用户的应用。

如果 user1 正在我的 iOS 应用程序上查看 user2 的个人资料,我希望在 user2 的个人资料上设置一个按钮(当被 user1 按下时)将打开 user1 的 Facebook 应用程序,以“返回”或“完成”显示 user2 的 Facebook 墙按钮将 user1 带回我的应用程序。

我认为这很容易,但我找不到任何相关信息。

  1. 当用户在我的 iOS 应用上创建帐户时,我如何获取 URL 或信息以访问用户 Facebook Wall?
  2. 然后如何创建链接以打开 Facebook 应用并显示所述用户的 Facebook 墙?

感谢您的帮助:)

【问题讨论】:

    标签: ios xcode facebook facebook-ios-sdk deep-linking


    【解决方案1】:

    我想通了!

    我首先遵循了这个教程:http://www.appcoda.com/ios-programming-facebook-login-sdk/

    然后我根据需要对其进行了修改。

    下面是我的应用程序代码

    在 AppDelegate.m 中

    #import <FacebookSDK/FacebookSDK.h>
    ...
    - (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        ...
        [FBLoginView class];
        [FBProfilePictureView class];
    }
    ...
    -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
    
        return [FBAppCall handleOpenURL:url
                  sourceApplication:sourceApplication];
    }
    

    在 CreateAccountConnectSocialMediaViewController.h 中

    #import <UIKit/UIKit.h>
    #import <FacebookSDK/FacebookSDK.h>
    
    @interface CreateAccountConnectSocialMediaViewController : UIViewController <FBLoginViewDelegate>
    
        @property (strong, nonatomic) IBOutlet UIView *socialMediaView;
        - (IBAction)nextButton:(UIButton *)sender;
        - (IBAction)openProfileButton:(UIButton *)sender;
    
    @end
    

    在 CreateAccountConnectSocialMediaViewController.m 中

    @interface CreateAccountConnectSocialMediaViewController ()
    @property FBLoginView *fbLoginButton;
    @property NSString *fbUserID;
    @end
    
    @implementation CreateAccountConnectSocialMediaViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        //Create CUSTOM FB Button
        self.fbLoginButton = [[FBLoginView alloc] init];
        for (id loginObject in self.fbLoginButton.subviews)
        {
            if ([loginObject isKindOfClass:[UIButton class]])
            {
                UIButton * loginButton =  loginObject;
                UIImage *loginImage = [UIImage imageNamed:@"FB_Hover.png"];
                [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
    
            }
            if ([loginObject isKindOfClass:[UILabel class]])
            {
                UILabel *loginLabel =  loginObject;
                loginLabel.text = @"";
                loginLabel.frame = CGRectMake(0, 0, 0, 0);
            }
        }
        self.fbLoginButton.delegate = self;
        self.fbLoginButton.readPermissions = @[@"public_profile", @"email"];
        self.fbLoginButton.frame = CGRectMake(0, 0, 46, 46);
        [self.socialMediaView addSubview:self.fbLoginButton];
    
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    //Change the ICON to denote the user is logged in
    -(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
        for (id loginObject in self.fbLoginButton.subviews)
        {
            if ([loginObject isKindOfClass:[UIButton class]])
            {
                UIButton *loginButton =  loginObject;
                UIImage *loginImage = [UIImage imageNamed:@"FB_Static.png"];
                [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
    
            }
            if ([loginObject isKindOfClass:[UILabel class]])
            {
                UILabel *loginLabel =  loginObject;
                loginLabel.text = @"";
                loginLabel.frame = CGRectMake(0, 0, 0, 0);
            }
        }
    
    }
    
    //Grab the users Apped Scoped ID, to use in going to his/her page later
    -(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
        self.fbUserID = user.objectID;
    }
    
    Change the ICON to denote the user is NOT logged in
    -(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
        for (id loginObject in self.fbLoginButton.subviews)
        {
            if ([loginObject isKindOfClass:[UIButton class]])
            {
                UIButton * loginButton =  loginObject;
                UIImage *loginImage = [UIImage imageNamed:@"FB_Hover.png"];
                [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
                [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
                [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
    
            }
            if ([loginObject isKindOfClass:[UILabel class]])
            {
                UILabel * loginLabel =  loginObject;
                loginLabel.text = @"";
                loginLabel.frame = CGRectMake(0, 0, 0, 0);
            }
        }
    
    }
    
    -(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
        NSLog(@"%@", [error localizedDescription]);
    }
    
    
    - (IBAction)nextButton:(UIButton *)sender {
        //Go to next CreateAccount View Controller
        [self performSegueWithIdentifier:@"accountCreatedSegue1" sender:self];
    }
    
    //Open the user's profile in the native FB App or
    //the browser if the native FB app doesn't exist
    - (IBAction)openProfileButton:(UIButton *)sender {
        NSString *urlString = [NSString stringWithFormat:@"fb://profile?app_scoped_user_id=%@", self.fbUserID];
        NSLog(@"urlString = %@", urlString);
        NSURL *url = [NSURL URLWithString:urlString];
        [[UIApplication sharedApplication] openURL:url];
    }
    @end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多