链接到用户';iOS应用中的Facebook墙
我一直在寻找指导,但我在这里和网络上找到的大部分是“如何从iOS应用程序发布到Facebook”。我的问题不同 我有一个有多个用户的应用程序 如果user1正在我的iOS应用程序上查看user2的个人资料,我希望在user2的个人资料上有一个按钮(当user1按下时)可以打开user1的Facebook应用程序,显示user2的Facebook墙,并有一个“后退”或“完成”按钮将user1带回我的应用程序 我想这很容易,但我找不到任何相关信息链接到用户';iOS应用中的Facebook墙,ios,xcode,facebook,facebook-ios-sdk,deep-linking,Ios,Xcode,Facebook,Facebook Ios Sdk,Deep Linking,我一直在寻找指导,但我在这里和网络上找到的大部分是“如何从iOS应用程序发布到Facebook”。我的问题不同 我有一个有多个用户的应用程序 如果user1正在我的iOS应用程序上查看user2的个人资料,我希望在user2的个人资料上有一个按钮(当user1按下时)可以打开user1的Facebook应用程序,显示user2的Facebook墙,并有一个“后退”或“完成”按钮将user1带回我的应用程序 我想这很容易,但我找不到任何相关信息 当用户在我的iOS应用程序上创建帐户时,如何获取ur
#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];
}
#导入
...
-(BOOL)应用程序:(UIApplication*)应用程序IDFinishLaunchWithOptions:(NSDictionary*)启动选项
{
...
[FBLoginView类];
[FBProfilePictureView类];
}
...
-(BOOL)应用程序:(UIApplication*)应用程序openURL:(NSURL*)url源应用程序:(NSString*)源应用程序注释:(id)注释{
返回[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:UIViewController
@属性(强、非原子)IBUIView*socialMediaView;
-(iAction)下一个按钮:(ui按钮*)发送器;
-(iAction)openProfileButton:(UIButton*)发送器;
@结束
在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
@interface CreateAccountConnectSocialMediaViewController()
@属性FBLoginView*fbLoginButton;
@属性NSString*fbUserID;
@结束
@实现CreateAccountConnectSocialMediaViewController
-(无效)viewDidLoad{
[超级视图下载];
//创建自定义FB按钮
self.fbLoginButton=[[FBLoginView alloc]init];
for(self.fbLoginButton.subview中的id loginObject)
{
if([loginObject是类的种类:[UIButton类]])
{
UIButton*loginButton=loginObject;
UIImage*loginImage=[UIImage ImageName:@“FB_Hover.png”];
[loginButton setBackgroundImage:loginImage for状态:UIControlStateNormal];
[登录按钮setBackgroundImage:nil for状态:UIControlStateSelected];
[登录按钮setBackgroundImage:nil for状态:UIControlStateHighlighted];
}
if([loginObject是类的种类:[UILabel类]])
{
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];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
//更改图标以表示用户已登录
-(无效)loginView显示日志用户:(FBLoginView*)loginView{
for(self.fbLoginButton.subview中的id loginObject)
{
if([loginObject是类的种类:[UIButton类]])
{
UIButton*loginButton=loginObject;
UIImage*loginImage=[UIImage ImageName:@“FB_Static.png”];
[loginButton setBackgroundImage:loginImage for状态:UIControlStateNormal];
[登录按钮setBackgroundImage:nil for状态:UIControlStateSelected];
[登录按钮setBackgroundImage:nil for状态:UIControlStateHighlighted];
}
if([loginObject是类的种类:[UILabel类]])
{
UILabel*loginLabel=loginObject;
loginLabel.text=@;
loginLabel.frame=CGRectMake(0,0,0,0);
}
}
}
//抓取用户的Apped作用域ID,以便在以后转到他/她的页面时使用
-(void)loginView蚀刻教育信息:(FBLoginView*)loginView用户:(id)用户{
self.fbUserID=user.objectID;
}
更改图标以表示用户未登录
-(无效)loginView显示LoggeDoutUser:(FBLoginView*)loginView{
for(self.fbLoginButton.subview中的id loginObject)
{
if([loginObject是类的种类:[UIButton类]])
{
UIButton*loginButton=loginObject;
UIImage*loginImage=[UIImage ImageName:@“FB_Hover.png”];
[loginButton setBackgroundImage:loginImage for状态:UIControlStateNormal];
[登录按钮setBackgroundImage:nil for状态:UIControlStateSelected];
[登录按钮setBackgroundImage:nil for状态:UIControlStateHighlighted];
}
if([loginObject是类的种类:[UILabel类]])
{
UILabel*loginLabel=loginObject;
loginLabel.text=@;
loginLabel.frame=CGRectMake(0,0,0,0);
}
}
}
-(无效)loginView:(FBLoginView*)loginView句柄错误:(N错误*)错误{
NSLog(@“%@,[错误本地化描述]);
}
-(iAction)下一个按钮:(ui按钮*)发送器{
//转到下一个CreateCount视图控制器
[self-PerformsgueWithIdentifier:@“accountCreatedSegue1”发件人:self];
}
//在本机FB应用程序中打开用户配置文件,或
//如果本机FB应用程序不存在,请打开浏览器
-(iAction)openProfileButton:(UIButton*)发送器{
NSString*urlString=[NSString stringWithFormat:@“fb://profile?app_scoped_user_id=%@”,self.fbUserID];
NSLog(@“urlString=%@”,urlString);
NSURL*url=[NSURL URLWithString:urlString];
[[UIApplication sharedApplication]openURL:url];
}
@结束