开发者

Facebook iOS - handleOpenURL & Tabbar Application

开发者 https://www.devze.com 2023-03-06 01:13 出处:网络
I\'m having difficulties getting the Facebook Log 开发者_如何学JAVAIn to kick back to the right view in my app and call the appropriate facebook functions.

I'm having difficulties getting the Facebook Log 开发者_如何学JAVAIn to kick back to the right view in my app and call the appropriate facebook functions.

In the example Facebook has simply [controller facebook] that is the view they start with. I am using a tabbar application though so I don't have the necessary reference. I made a pointer to the desired view and used it... it opened correctly but would not call any of the methods associated with facebook, specifically:

(void)fbDidLogin;

(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [[*NotReferencedViewController* facebook] handleOpenURL:url];
}

Has anyone else run into this?


Not sure what example you're talking about, but you should create and store your Facebook object in a central place such as your Model or UIApplicationDelegate. Then it would be accessible through singletons so you always have access to it, for example:

[[UIApplication sharedApplication] delegate].facebook

So you can then access the facebook object from whatever view controllers need it.

When you do something like

NSArray* permissions =  [[NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil] retain];

[facebook authorize:permissions delegate:self];

specifying delegate:self means you will implement methods in that class that Facebook can call to inform you of certain events. One of those methods is fbDidLogin, and in there you can do whatever you need to:

-(void)authorizeFacebook {
    NSArray* permissions =  [NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil];

    [facebook authorize:permissions delegate:self];
}

// if the authorization succeeds it will come back to your app and call the method below
-(void)fbDidLogin {
    // switch view, call the facebook graph, or do whatever else you like
}

You could do this in the app delegate itself, or in a view controller.

You can see the facebook delegate methods by inspecting the .h files of the facebook SDK: Facebook.h, FacebookRequest.h, etc.

Edit

And your handleOpenURL: method should look exactly as it does in fb's example (assuming you are not handling other url schemes):

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    return [facebook handleOpenURL:url]; 
}

http://developers.facebook.com/docs/guides/mobile/#ios

0

精彩评论

暂无评论...
验证码 换一张
取 消