I am building an app that has a navigationitem in the navigation bar.
I am trying to understand how to use the facebook sdk to connect to facebook (authenticating) when the button is clicked.
This is not some special viewcontroller or something.
I have seen this:
http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/authenticate/
but in there i need to create some things in the delegate (like a UINavigationController) that i can't use because i am using a UITabBarController..
how can i implement facebook login and session creation just from pushing the UINavigationItem?
Here is my AppDelegate.h:
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UITabBarController *tbc;
#property (strong, nonatomic) FBSession *session;
#end
And my AppDelegate.m:
#import "AppDelegate.h"
#import "StatusView.h"
#import "JokesView.h"
#import "HomeView.h"
#import "TopTenView.h"
#import "UploadView.h"
#implementation AppDelegate
#synthesize tbc;
#synthesize window = _window;
#synthesize session = _session;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UINavigationController*nav1 = [[UINavigationController alloc]init];
UINavigationController*nav2 = [[UINavigationController alloc]init];
UINavigationController*nav3 = [[UINavigationController alloc]init];
UINavigationController*nav4 = [[UINavigationController alloc]init];
UINavigationController*nav5 = [[UINavigationController alloc]init];
StatusView*page1 = [[StatusView alloc]initWithNibName:#"StatusView" bundle:nil];
JokesView*page2 = [[JokesView alloc]initWithNibName:#"JokesView" bundle:nil];
HomeView*page3 = [[HomeView alloc]initWithNibName:#"HomeView" bundle:nil];
TopTenView*page4 = [[TopTenView alloc]initWithNibName:#"TopTenView" bundle:nil];
UploadView*page5 = [[UploadView alloc]initWithNibName:#"UploadView" bundle:nil];
page1.title = #"סטטוסים";
page2.title = #"תמונות";
page3.title = #"ראשי";
page4.title = #"Top 10";
page5.title = #"העלאה";
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:#"Status"
image:[UIImage imageNamed:#"tbc-status.png"] tag:1];
[nav1 setTabBarItem:tab1];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:#"Jokes"
image:[UIImage imageNamed:#"tbc-jokes.png"] tag:1];
[nav2 setTabBarItem:tab2];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:#"Home"
image:[UIImage imageNamed:#"tbc-home.png"] tag:1];
[nav3 setTabBarItem:tab3];
UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:#"Tpp10"
image:[UIImage imageNamed:#"tbc-topten.png"] tag:1];
[nav4 setTabBarItem:tab4];
UITabBarItem *tab5 = [[UITabBarItem alloc] initWithTitle:#"Upload"
image:[UIImage imageNamed:#"tbc-upload.png"] tag:1];
[nav5 setTabBarItem:tab5];
[nav1 pushViewController:page1 animated:NO];
[nav2 pushViewController:page2 animated:NO];
[nav3 pushViewController:page3 animated:NO];
[nav4 pushViewController:page4 animated:NO];
[nav5 pushViewController:page5 animated:NO];
tbc = [[UITabBarController alloc]init];
tbc.viewControllers = [NSArray arrayWithObjects:nav5,nav4,nav3,nav2,nav1, nil];
tbc.selectedIndex = 2;
// NavBar Design
UIImage *navbarPortrait = [[UIImage imageNamed:#"topbar.jpg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *navbarLandscape = [[UIImage imageNamed:#"topbar.jpg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:navbarPortrait
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:navbarLandscape
forBarMetrics:UIBarMetricsLandscapePhone];
// NavBar Design End
// TabBar Design
UIImage *tabBackground = [[UIImage imageNamed:#"tbcb3ack.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[tbc tabBar] setBackgroundImage:tabBackground];
// TabBar Design End
[self.window addSubview:tbc.view];
self.window.rootViewController = self.tbc;
// Push Notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
// Push Notifications End
// Facebook Code Start
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Not Logged in"
// message:#"You Log in to use all the fearues in this app"
// delegate:nil
// cancelButtonTitle:#"OK"
// otherButtonTitles:nil];
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
// To-do, show logged in view
} else {
//[alert show];
}
// Facebook Code End
[self.window makeKeyAndVisible];
return YES;
}
// Facebook sdk code Start
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
withSession:self.session];
}
// Facebook sdk code End
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[FBAppCall handleDidBecomeActiveWithSession:self.session];
}
#pragma mark Template generated code
#end
These are after i used the facebook ios authentication tutorial, before the actual fb session changes and login button.
There really are two parts to solving this problem. You first need to define a UIButton to be a UINavigationItem which will do your login (or log out) on click. And second, your app has to be ready to accept the login event. I'm not sure which part is causing you more trouble, but here's how you set up part one, the button:
UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
loginButton.frame = CGRectMake(0.0f, 0.0f, 75.0f, 44.0f);
[loginButton setTitle:#"Login" forState:UIControlStateNormal];
[loginButton addEventHandler:^(id sender)
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:loginButton];
As for part two, you need to define the sessionStateChanged function in this view controller. To save you trouble, here's the general structure that you need for the sessionStateChanged method:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
// Connected to facebook... so go to your next view controller
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
// Login failed
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
You'll also need to implement a lot of other things, especially in your app delegate. I'm happy to write out more code samples for you, but help me understand what you want to see next.
UPDATE
Ok, so now that I understand you want to have this facebook button stay with you on the nav bar, I would subclass the nav controller, set the subclasss to be its own delegate, and add the facebook button to each view controller that's added. The thing to note is, the navigation bar that's drawn uses the navigationItem of each view controller that's added to the navigation controller. So technically, you need to add this same button to every view controller that's pushed or popped in and out of the navigation controller. Instead of copy-pasting code around or even setting up a utility class (or super class) that all your view controllers use to insert this facebook button, a quick and dirty way is to create a single button in a navigation controller subclass and insert that same button as each view controller is shown. So here's a very bare bones version of what the navigation controller subclass might look like this in its implementation file:
#interface MYNavigationController () <UINavigationControllerDelegate>
#property (nonatomic, strong) UIButton *facebookButton;
#end
#implementation MYNavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
// Set this subclass as its own delegate to be able receive the willShowViewController: method
self.delegate = self;
// Create a shared facebook button
_facebookButton = [UIButton buttonWithType:UIButtonTypeCustom];
_facebookButton.frame = CGRectMake(0.0f, 0.0f, 75.0f, 44.0f);
[_facebookButton setTitle:#"Login" forState:UIControlStateNormal];
[_facebookButton
addTarget:self
action:#selector(onFacebookButtonClick:)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// As each view controller is about to be shown, change the view controller's
// navigationItem to have this facebook button as its right bar button
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.facebookButton];
}
- (void)onFacebookButtonClick:(id)sender
{
// Handle the click event when the facebook button is clicked
// You need to have logic here to know if the session is open or not
// Of course, when the session isn't open, then open a new session (ie. login)
// and when the session IS open, then close the session (ie. logout)
[FBSession
openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler: ^(FBSession *session, FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
// Connected to facebook so...
// 1. change the button text to say "logout" instead of "login"
// 2. go to your next view controller
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
// Login failed so revert everything to pre-login state
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
And then, simply use this MYNavigationController as your navigation controller class. Don't forget to go through the facebook ios authentication tutorial for a guided tour of how to set up your app (there's plenty of frameworks to add, infoplist changes, etc).
Happy to help more if you need it!
Update #2
Because your window's root view controller is a UITabBarController, then we can use that as the owner of the facebookButton, which is shared between all UINavigationControllers. At a high level, the logic hasn't changed from my previous code sample. You're creating a single button somewhere, that's being added to every view controller that's shown by your navigation controllers. In order to do this, you need to first create a UITabBarController subclass (again, mine is called MYTabBarController, but you can call it whatever you want). And it will look something like this in MYTabBarController.m:
#import "MYTabBarController.h"
#import <FacebookSDK/FacebookSDK.h>
#implementation MYTabBarController
- (UIButton *)facebookButton
{
if (! _facebookButton)
{
// Create a shared facebook button on demand
_facebookButton = [UIButton buttonWithType:UIButtonTypeCustom];
_facebookButton.frame = CGRectMake(0.0f, 0.0f, 75.0f, 44.0f);
[_facebookButton setTitle:#"Login" forState:UIControlStateNormal];
[_facebookButton
addTarget:self
action:#selector(onFacebookButtonClick:)
forControlEvents:UIControlEventTouchUpInside];
}
return _facebookButton;
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// As each view controller is about to be shown, change the view controller's
// navigationItem to have this facebook button as its right bar button
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.facebookButton];
}
- (void)onFacebookButtonClick:(id)sender
{
// Handle the click event when the facebook button is clicked
// You need to have logic here to know if the session is open or not
// Of course, when the session isn't open, then open a new session (ie. login)
// and when the session IS open, then close the session (ie. logout)
[FBSession
openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler: ^(FBSession *session, FBSessionState state, NSError *error)
{
[self sessionStateChanged:session state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
// Connected to facebook so...
// 1. change the button text to say "logout" instead of "login"
// eg. [self.facebookButton setTitle:#"Logout" forState:UIControlStateNormal];
// 2. go to your next view controller
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
// Login failed so revert everything to pre-login state
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
The corresponding MYTabBarController.h will need to have at least a button defined and the fact it conforms to the UINavigationControllerDelegate protocol:
#interface MYTabBarController: UITabBarController<UINavigationControllerDelegate>
#property (nonatomic, strong) UIButton *facebookButton;
Finally, your app delegate's application:didFinishLaunchingWithOptions: needs to make a small change. It needs to declare the tab bar as the delegate for each of your UINavigationControllers:
// Set the navigation controller delegates to be the tabbar in order to hook into the willShowViewController: method
nav1.delegate = tbc;
nav2.delegate = tbc;
nav3.delegate = tbc;
nav4.delegate = tbc;
nav5.delegate = tbc;
That should do it. Hopefully you can take it from here. Good luck!
When you push to a viewController, you should alloc viewControler before. And you can implement facebook login and session creation in alloc function of viewController.
That's posible. You can create facebook login and session in appDelegate. When you need show facebook view, you can call a function to popup facebook view.
i have a problem in getting the GADInterstitial custom ads i have tried this code
if(nil != m_pBannerView)
{
m_pBannerView.delegate = nil;
[m_pBannerView release];
m_pBannerView = nil;
}
m_pBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
m_pBannerView.delegate = self;
m_pBannerView.rootViewController = self;
m_pBannerView.adUnitID = #"AdMob Publisher ID";
m_pBannerView.rootViewController = self;
[self.view addSubview:m_pBannerView];
GADRequest *request = [GADRequest request];
request.testing = YES;
[m_pBannerView loadRequest:request];
if(nil != m_pInterstitial)
{
[m_pInterstitial release];
m_pInterstitial = nil;
}
m_pInterstitial = [[GADInterstitial alloc] init];
m_pInterstitial.delegate = self;
m_pInterstitial.adUnitID = #"INTERSTITIAL_AD_UNIT_ID";
GADRequest *interstialRequest = [GADRequest request];
interstialRequest.testing = YES;
[m_pInterstitial loadRequest: interstialRequest];
}
And in GADInterstitial Delegates i am calling [ad presentFromRootViewController:self];
but still i am not able to get the custom ads please help me.
You have to use your own unique id for adUnitID property
GADInterstitial is an interesting way to show ads in your Apps, and kind of a tricky one too. Following this example, lets pursue the following steps:
First we need to set up the environment for them to show at all.
Download the GoogleAdMobAdsSdkiOS, preferably the latest. Add
the SDK to your project, but do remember to delete the example
Projects in the AddOns folder in the SDK.
Next, add the following frameworks in your Project>>Build
Phases>>Link Binary With Libraries:
AdSupport.framework (select Optional if catering for < iOS7)
StoreKit.framework
CoreData.framework
CoreAudio.framework
AVFoundation.framework
MessageUI.framework
AudioTool.framework
libGoogleAdMobAds.a (placed in the SDK folder)
The basics are complete. Now we need to select the ViewController we wish to see our Ads in. So here's some code, here we import the header for GADInterstitialDelegate and extend it with our MainViewController.h:
#import "GADInterstitialDelegate.h"
#define kSampleAdUnitID #"/6253334/dfp_example_ad/interstitial"
#class GADInterstitial;
#class GADRequest;
#interface MainViewController : UIViewController<GADInterstitialDelegate>
{
BOOL isLoaded_;
NSTimer *quickie_;
}
#property(nonatomic, strong) GADInterstitial *interstitial;
//Make sure the delegate is handled properly.
Now we need to move to the implementation i.e. in MainViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// FOLLOW THE CODE BELOW FOR ADMOD INTERESTIAL IMPLEMENTATION
[self initializeAds];
quickie_ = [[NSTimer alloc] init];
quickie_ = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(showAdd) userInfo:nil repeats:YES];
}
-(void)showAdd
{
if(isLoaded_ && [quickie_ isValid])
{
[quickie_ invalidate];
quickie_ = nil;
[self.interstitial presentFromRootViewController:self];
}
}
- (GADRequest *)request
{
GADRequest *request = [GADRequest request];
return request;
}
-(void)initializeAds
{
// Create a new GADInterstitial each time. A GADInterstitial will only show one request in its
// lifetime. The property will release the old one and set the new one.
self.interstitial = [[GADInterstitial alloc] init];
self.interstitial.delegate = self;
// Note: kSampleAdUnitId is a staticApId for example purposes. For personal Ads update kSampleAdUnitId with your interstitial ad unit id.
self.interstitial.adUnitID = kSampleAdUnitID;
[self.interstitial loadRequest:[self request]];
}
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.loadingSpinner.center = CGPointMake(CGRectGetWidth(self.view.bounds) / 2, self.loadingSpinner.center.y);
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial
{
isLoaded_ = YES;
}
- (void)interstitial:(GADInterstitial *)interstitial didFailToReceiveAdWithError:(GADRequestError *)error
{
isLoaded_ = NO;
}
//----ADS IMPLEMENTATION TILL HERE--->//
The timer "quickie_" here constantly checks if the Ad has successfully loaded and when it does, it shoots the Ad on the ViewController if the user still is on it. The static kSampleAdUnitID is a sampleId that always works. Thats it. Run your code and find your Interstitial Ad on your ViewController of choice.
Hope I helped. Cheers! :)
I am developing a iPhone application which sends tweets to twitter. For this I am using SA_OAuthTwitterEngine + MGTwitterEngine classes.
I register applicaiton to www.twitter.com/apps and pass Consumer key and Consumer secret to controller my code is this.
if(!_engine){
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
_engine.consumerKey = slPcFUjUh5y1hex0zvEhPg;
_engine.consumerSecret = u6ydovMdP9yeiVqDukVhIzZPgJR9XDPUwfxymzNs;
}
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller){
[self presentModalViewController: controller animated: YES];
intTwitterFlag = 1;
}
Previously on twitter.com/apps I select Application type = client and my application will generate PIN and accessToken. But when i change my Application type = Browser it cannot generate PIN and accessToken.
Previously when application type is client i am giving user name and password and then control return to my application from the webview but now after entering user name and password it cannot dismissModalViewController but showing Select and Copy the PIN.
Thank you for your time and any help you can give me!
Here it is:just replace the method in SA_OAuthTwitterController.m:
- (void) webViewDidFinishLoad: (UIWebView *) webView {
_loading = NO;
//[self performInjection];
if (_firstLoad) {
[_webView performSelector: #selector(stringByEvaluatingJavaScriptFromString:) withObject: #"window.scrollBy(0,200)" afterDelay: 0];
_firstLoad = NO;
} else {
/*
NSString *authPin = [self locateAuthPinInWebView: webView];
NSLog(#"authPin: %#", authPin);
if (authPin.length) {
[self gotPin: authPin];
return;
}
NSString *formCount = [webView stringByEvaluatingJavaScriptFromString: #"document.forms.length"];
if ([formCount isEqualToString: #"0"]) {
[self showPinCopyPrompt];
}*/
//*****************************************************
// This is to bypass the pin requirement
// in case the call back URL is set in Twitter settings
//*****************************************************
[_engine requestAccessToken];
if ([_delegate respondsToSelector: #selector(OAuthTwitterController:authenticatedWithUsername:)])
{
[_delegate OAuthTwitterController: self authenticatedWithUsername: _engine.username];
}
[self performSelector: #selector(dismissModalViewControllerAnimated:) withObject: (id) kCFBooleanTrue afterDelay: 1.0];
//[self dismissModalViewControllerAnimated:YES];
}
[UIView beginAnimations: nil context: nil];
_blockerView.alpha = 0.0;
[UIView commitAnimations];
if ([_webView isLoading]) {
_webView.alpha = 0.0;
} else {
_webView.alpha = 1.0;
}
}
I too faced the same issue, and i just removed callback url from the twitter app settings. For my surprise login proceeds without any issue.
The replacement for this method
(void) webViewDidFinishLoad: (UIWebView *) webView
in the class SA_OAuthTwitterController.m works well.
Its better to use xAuth route for mobile apps
http://dev.twitter.com/pages/xauth
check XAuthTwitterEngine which implements xauth for the MGTwitterEngine
I am using Facebook in my music application where user post comment on wall paper after listening the songs . So problem arises that user have to login again for next song. so please provide me code for session retains when he clicked on the tab where it written "keep me login".
Thanks
I have a file called FacebookHelper.m, here is the code there:
- (id)init {
if (self = [super init]) {
session_ = [[FBSession sessionForApplication:kAPIKey secret:kApplicationSecret delegate:self] retain];
[session_ resume];
}
return self;
}
If you want to control the login dialog yourself, here is the code:
- (void)loginByShowingDialog {
self.isDialogShown = YES;
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:self.session] autorelease];
dialog.delegate = self;
[dialog show];
}
For your cases, I think you only need to get the session back and resume it.
The Facebook connect code is eluding me a bit.
I have no problem doing a login, and a wall post, however, I simply can not
figure out how the delegate methods for the FBDialog andFBStreamDialog is supposed to work.
- (void)postToWall {
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"JSONpost code"];
[dialog show];
}
I adhere to these protocols in my controller:
<FBDialogDelegate, FBSessionDelegate, FBRequestDelegate>
I then implement the two methods:
- (void) dialogDidCancel:(FBDialog *)dialog {
NSLog(#"Failed");
}
- (void) dialogDidSucceed:(FBDialog *)dialog {
NSLog(#"Success");
}
After I tap "publish" and the postToWall methods is done executing the Facebook "pop up" in the UI is empty, except a small "X" in the top right corner and a "F" (facebook logo) in the top left corner.
The UI will stay there until I tap the "X", this results in the dialogDidCancel delegate method being called. The post data is showing up on the Facebook page, everything seems to work.
Why is thedialogDidSucceedmethod never called? I need this to release my facebook controller and restore the UI back to where the user was before "starting" FB Connect.
Thank You:)
Facebook has fixed this issue, as you can see from their post at:
http://bugs.developers.facebook.com/show_bug.cgi?id=10531
I see where the problem is, but not sure what if anything we can do about it. It happens in the UIWebView Delegate method in the FBDialog class. If you click the Skip button, the request.URL is populated with 'fbconnect:success', it should really be 'fbconnect:cancel' but other people have already pointed out this problem out before. Our problem is that when you click the Publish button, the request.URL should read 'fbconnect:success' however, it ends up containing 'http://www.facebook.com/fbconnect/prompt_feed.php', so, it never calls dismissWithSuccess:YES or dialogDidSucceed.
I can't find anyplace where the Publish button's post URL is set, but if we can change it to fbconnect:success, it might work.
FBDialog.m
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL* url = request.URL;
if ([url.scheme isEqualToString:#"fbconnect"]) {
if ([url.resourceSpecifier isEqualToString:#"cancel"]) {
[self dismissWithSuccess:NO animated:YES];
} else {
[self dialogDidSucceed:url];
}
return NO;
} else if ([_loadingURL isEqual:url]) {
return YES;
} else if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if ([_delegate respondsToSelector:#selector(dialog:shouldOpenURLInExternalBrowser:)]) {
if (![_delegate dialog:self shouldOpenURLInExternalBrowser:url]) {
return NO;
}
}
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
} else {
return YES;
}
}