Satyam
Satyam

Reputation: 15894

iOS - Facebook single sign on - from my view controller

In the documentation from facebook to integrate their sdk in iOS app, they mentioned everything in app delegate.

But in my application, i've settings view which has option for "Facebook".

When user clicks that then only i want to enable single sign on from my application. This can be done by creating facebook object etc in my settings view controller. But in app delegate, they are asking to ad the following code:

// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [facebook handleOpenURL:url]; 
}

// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
    sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [facebook handleOpenURL:url]; 
}

And both the above methods has to be implemented in app delegate class with "facebook" as object. But I'm creating my facebook object in my settings view controller. How should I handle this situation?

Upvotes: 1

Views: 387

Answers (2)

benathon
benathon

Reputation: 7633

Add this to your AppDelegate.m (and add it to the .h header file)

+ (AppDelegate*) sharedAppDelegate {
    return (AppDelegate*) [UIApplication sharedApplication].delegate;
}

Include the header file and do this to access your facebook object from any view controller:

[[AppDelegate sharedAppDelegate] facebook]

Upvotes: 1

Satyam
Satyam

Reputation: 15894

as mentioned in the docs, I'm creating the facebook object and calling the methods in app delegate from the settings view

Upvotes: 0

Related Questions