2 Different FBConnect for 2 Different Views?

Discussion in 'iOS Programming' started by newtoiphonesdk, Aug 26, 2010.

  1. newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    I am using the tutorial from github to implement FBConnect in my App. What I want is on one view the option to post to wall with the dialog.attachment showing static text that invites people to church. The other viewController contains a blog. I would like the FBConnect there to post the blog to Facebook. Here is the code I have:
    Code:
    - (void)viewDidLoad {BellAvenueAppDelegate *appDelegate =
    	(BellAvenueAppDelegate *)   [[UIApplication
    								  sharedApplication]delegate];
    	if (appDelegate._session == nil){
    		appDelegate._session = [FBSession
    								sessionForApplication:_APP_KEY
    								secret:_SECRET_KEY delegate:self];
    	}
    	if(self.loginButton == NULL)
    		self.loginButton = [[[FBLoginButton alloc] init] autorelease];
    	loginButton.frame = CGRectMake(124, 91, 72, 37);
    	[self.view addSubview:loginButton];
    	
        [super viewDidLoad];
    }
    
    /*
     // Override to allow orientations other than the default portrait orientation.
     - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     // Return YES for supported orientations
     return (interfaceOrientation == UIInterfaceOrientationPortrait);
     }
     */
    
    - (void)didReceiveMemoryWarning {
    	// Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    	
    	// Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
    	// Release any retained subviews of the main view.
    	// e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [username release];
    	[usersession release];
    	[loginButton release];
    	[super dealloc];
    	
    }
    - (void)session:(FBSession*)session didLogin:(FBUID)uid {
    	self.usersession =session;
    	NSLog(@"User with id %lld logged in.", uid);
    	[self getFacebookName];
    }
    
    - (void)getFacebookName {
    	NSString* fql = [NSString stringWithFormat:
    					 @"select uid,name from user where uid == %lld",
    					 self.usersession.uid];
    	NSDictionary* params =
    	[NSDictionary dictionaryWithObject:fql
    								forKey:@"query"];
    	[[FBRequest requestWithDelegate:self]
    	 call:@"facebook.fql.query" params:params];
    	self.post=YES;
    }
    
    - (void)request:(FBRequest*)request didLoad:(id)result {
    	if ([request.method isEqualToString:@"facebook.fql.query"]) {
    		NSArray* users = result;
    		NSDictionary* user = [users objectAtIndex:0];
    		NSString* name = [user objectForKey:@"name"];
    		self.username = name;
    		
    		if (self.post) {
    			[self postToWall];
    			self.post = NO;
    		}
    	}
    }
    
    - (void)postToWall {
    	
    	FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
    	dialog.userMessagePrompt = @"Enter Your Message Here:";
    	dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Join Us For Morning Services\",\"href\":\"http://bellavenue.org\",\"caption\":\"We Love Our Visitors!\",\"description\":\"1600 Bell Amarillo, TX\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.316apps.com/lovevisitors.jpg\",\"href\":\"http://itunes.apple.com/us/app/bell-avenue-church-of-christ/id379478795?mt=8\"}],\"properties\":{\"Our Facebook Page!\":{\"text\":\"Bell Avenue Facebook Group\",\"href\":\"http://www.facebook.com/pages/Bell-Avenue-church-of-Christ-Amarillo-TX/263538619113?ref=ts\"}}}"];
    	[dialog show];
    	
    }
    That is the static invitation to church one. Everything is the same on the other one, except I change the Post to Wall Line to this:
    Code:
    - (void)postToWall {
    	self.currentURL = sermons.request.URL.absoluteString;
    	FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
    	dialog.userMessagePrompt = @"Enter Your Message Here:";
    	dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"href\":\"http://bellavenue.org\",\"caption\":\"We Love Our Visitors!\",\"description\":\"1600 Bell Amarillo, TX\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.316apps.com/lovevisitors.jpg\",\"href\":\"http://itunes.apple.com/us/app/bell-avenue-church-of-christ/id379478795?mt=8\"}],\"properties\":{\"Our Facebook Page!\":{\"text\":\"Bell Avenue Facebook Group\",\"href\":\"http://www.facebook.com/pages/Bell-Avenue-church-of-Christ-Amarillo-TX/263538619113?ref=ts\"}}}", self.currentURL];
    	[dialog show];
    	
    }
    However, I always get the exact same post on facebook, the first one. Is there a way to set it up like described here, or do I need to just pick one?

    While I'm here...How can you connect the Facebook login with an ActionSheet? I know now how to do an ActionSheet using Case Statements, but there are many different Void statements in the above code regarding Facebook. Do I put all of that in a case statement for a Facebook button or what?
     
  2. Rigter macrumors newbie

    Joined:
    Dec 29, 2010
    #2
    You've got the solution for this issue? :(

    Thanks!
     

Share This Page