如何检查Facebook是否登录设备?客观C [英] How to check if Facebook is loggedIN in device ? objective C
本文介绍了如何检查Facebook是否登录设备?客观C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UIButton
,我用它在用户的Facebook墙上分享。现在我不想使用FBLoginView登录,我想检查是否有一个Facebook应用程序,如果用户已经登录。 - (IBAction)pickFriendsList:(UIButton *)sender
{
FBFriendPickerViewController * friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = @Pick Friends;
[friendPickerController loadData];
//使用模态包装方法显示选择器。
[friendPickerController presentModallyFromViewController:self animated:YES处理程序:
^(FBViewController * sender,BOOL donePressed){
if(!donePressed){
return;
}
NSString * fid;
NSString * fbUserName;
for(id< FBGraphUser> user在friendPickerController.selection中)
{
NSLog(@\\\
user =%@ \\\
,user);
fid = user.id;
fbUserName = user.name;
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@test,@message,@http://webecoist.momtastic.com/wp-content/uploads/2009/01/nature- wonders.jpg,@picture,@Sample App,@name,fid,@tags,fid,@to,@106377336067638,@place,nil]
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@%@ / feed,fid]参数:params HTTPMethod:@POSTcompletionHandler:^(FBRequestConnection * connection,id result, NSError *错误)
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil参数:params处理程序:^(FBWebDialogResult结果,NSURL * resultURL,NSError *错误)
{
如果(错误)
{
//启动对话框或发布故事时出错。
NSLog(@错误发布故事);
}
else
{
if(result == FBWebDialogResultDialogNotCompleted){
//用户点击x图标
NSLog(@用户已取消故事出版);
}
else
{
//处理发布Feed回调
//告诉用户它有效。
}
}
}];
}];
}
}];
}
解决方案
假设你正在使用iOS 6 sdk。在这种情况下,使用以下代码(适用于设备):
if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook])
{
//用户已经使用iOS集成的FB登录a a c c b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b
$ b //用户未登录
}
注意:FBSession无法检查此条件。所以与FBSession的会话检查与上面的代码有不同的含义。
请问,
I am implementing the Facebook SDK into my app . I am using FBLoginView to login with Facebook. I have a UIButton
, which I'm using to share on a user's Facebook wall. Now I don't want to login using FBLoginView , i want to check if there is a Facebook app, and if the user has logged in.
- (IBAction)pickFriendsList:(UIButton *)sender
{
FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
friendPickerController.title = @"Pick Friends";
[friendPickerController loadData];
// Use the modal wrapper method to display the picker.
[friendPickerController presentModallyFromViewController:self animated:YES handler:
^(FBViewController *sender, BOOL donePressed) {
if (!donePressed) {
return;
}
NSString* fid;
NSString* fbUserName;
for (id<FBGraphUser> user in friendPickerController.selection)
{
NSLog(@"\nuser=%@\n", user);
fid = user.id;
fbUserName = user.name;
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"test", @"message", @"http://webecoist.momtastic.com/wp-content/uploads/2009/01/nature-wonders.jpg", @"picture", @"Sample App", @"name",fid,@"tags",fid,@"to",@"106377336067638",@"place", nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed",fid] parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
{
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
// Error launching the dialog or publishing a story.
NSLog(@"Error publishing story.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(@"User canceled story publishing.");
}
else
{
// Handle the publish feed callback
//Tell the user that it worked.
}
}
}];
}];
}
}];
}
解决方案
I am assuming that you are using iOS 6 sdk. In which case, Use below code (workable for device) :
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
//user is already logged in using iOS integrated FB a/c
}
else
{
//user is not logged in
}
Note: FBSession can't check this criteria. So session check with FBSession has a different meaning from above code.
Regards,
这篇关于如何检查Facebook是否登录设备?客观C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文