I have an application that uses a Tab Bar for control. In my thirdviewcontroller I have a webview that I would like to be able to program so that people can connect with facebook, and publish the link the webview is on to their facebook wall. I originally tested just the FBConnect without a webview present, and it worked fine. Afterwards, I added the UIWebView. It will build, but when the UIWebView is present, the FBConnect button will not appear. Here is my .h and .m codes.
.h:
.m:
UPDATE:
Ok I have it partially solved. Apparently I didn't get very much sleep last night and I have no idea why I did an awakefromnib and viewdidload statements. I moved
into the viewdidload, and the FBConnect button will now show. I can login, but when it tries to pull up the publish to wall part, it crashes. Here is what I have for the code for that part.
What I want it to do is to post a link of the current URL the user is on. I thought that setting up the NSString in the view did load and then setting the dialog.attachment to that NSString would work, but it constantly crashes. Any ideas?
.h:
Code:
#import <UIKit/UIKit.h>
#import "FBConnect.h"
#import "FBSession.h"
@interface ThirdViewController : UIViewController {
IBOutlet UIWebView *sermons;
IBOutlet UIActivityIndicatorView *activity;
NSTimer *timer;
FBLoginButton *loginButton;
UIAlertView *facebookAlert;
FBSession *usersession;
NSString *username;
BOOL post;
}
@property(nonatomic,retain) FBLoginButton *loginButton;
@property(nonatomic,retain) UIAlertView *facebookAlert;
@property(nonatomic,retain) FBSession *usersession;
@property(nonatomic,retain) NSString *username;
@property(nonatomic,assign) BOOL post;
@property (nonatomic, retain) UIActivityIndicatorView *activity;
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
-(void)getFacebookName;
-(void)postToWall;
@end
.m:
Code:
#import "ThirdViewController.h"
#import "BellAvenueAppDelegate.h"
#define _APP_KEY @"REMOVED FOR PRIVACY"
#define _SECRET_KEY @"REMOVED FOR PRIVACY"
@implementation ThirdViewController
@synthesize loginButton;
@synthesize facebookAlert;
@synthesize usersession;
@synthesize username;
@synthesize post;
- (void)awakeFromNib
{
[sermons loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/iphonesermons.html"]]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
NSString *currentURL = sermons.request.URL.absoluteString;
}
-(void)tick {
if(!sermons.loading)
[activity stopAnimating];
else
[activity startAnimating];
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
- (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 {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[username release];
[usersession release];
[loginButton release];
[sermons 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 currentURL];
[dialog show];
}
@end
Ok I have it partially solved. Apparently I didn't get very much sleep last night and I have no idea why I did an awakefromnib and viewdidload statements. I moved
Code:
[sermons loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/iphonesermons.html"]]];
NSString *currentURL = sermons.request.URL.absoluteString;
Code:
- (void)postToWall {
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter Your Message Here:";
dialog.attachment = [NSString currentURL];
[dialog show];
}