FBDialog cancel button callback - iphone

When user hits the Cancel button in the FBStreamDialog, which inherits from FBDialog, I am having trouble differentiating it from when user clicks on the Publish button. Seems that the callback FBDialog dismissWithSuccess is always passed with the status:NO regardless of which button is clicked. What am I doing wrong? Thanks!
Here's the class that handles all the FBConnect in my app:
#interface SocialMediaViewController : UIViewController <FBSessionDelegate, FBRequestDelegate, FBDialogDelegate> {...
Here's how I instantiated the login.
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:self.fbSession] autorelease];
dialog.delegate = self;
[dialog show];
Here's how I instantiated the FBStreamDialog.
FBStreamDialog* dialog = [[FBStreamDialog alloc] init];
dialog.delegate = self;
dialog.userMessagePrompt = #"Enter additional comment:";
dialog.attachment = [NSString stringWithFormat:#"{\"name\":\"My name string %#\"," "\"href\":\"http://xyz.com/\"," "\"caption\":\"placeholder-%#\",\"description\":\"%#\"," "\"properties\":{\"More like this\":{\"text\":\"XYZ website\",\"href\":\"http://XYZ.com/\"}}}", self.curReview.businessName, self.curReview.reviewType, self.curReview.reviewDetail];
[dialog show];

Add the following as the first line in FBDialog.m / webViewDidFinishLoad :
[_webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('cancel').onclick = function onclick(event) { window.location.href = 'fbconnect:cancel'; }"];
Bear in mind that Facebook doesn't let you "punish" users for canceling :-)

Related

App terminates on back button

I have a view controller "Gallery screen" namely, as user taps button "Gallery" it goes to that view controller. Now I have a web service call if any picture of particular outlet exists fetch it or else if it doesn't exist then show an AlertView saying "No image found". Now my problem is when user go to gallery screen if there is no image of that outlet and user hits back button before response of service "no image found" app terminates. I get that popup saying "no image found" on previous screen that i get after pressing back button as i "Ok" it, it terminates but THIS ONLY HAPPENS IN iOS 7. Please help and thanks in advance.
EDIT:
I have also tried to dealloc my objects but still the same issue. May be I'm missing something here is the code that I used.
-(void)dealloc
{
bllGalleryImages.delegate = nil;
bllGalleryImages = nil;
}
here is my viewDidLoad Method
-(void)viewDidLoad
{
[super viewDidLoad];
progress = [[MBProgressHUD alloc] init];
progress.labelText = #"Loading";
[progress showUsingAnimation:YES];
[self.view addSubview:progress];
scrl = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 100, 300, 300)];
scrl.scrollEnabled = YES;
scrl.minimumZoomScale=1.0;
scrl.maximumZoomScale=4.0;
scrl.delegate=self;
// Do any additional setup after loading the view from its nib.
}
here is my View will appear method
-(void)viewWillAppear:(BOOL)animated
{
[self userInterface];
[self callService];
}
here is my callService method
-(void)callService
{
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
[param setObject:#"xyz" forKey:#"DeveloperKey"];
[param setObject:outletObjForInfo.outlet_id forKey:#"outletID"];
bllGalleryImages = [[BLLAuthentication alloc] init];
bllGalleryImages.delegate = self;
[bllGalleryImages getGalleryImages:param];
}

Error when using Twitter to log in to my iPhone app

I am using Twitter login to enter in my app. But when I click on the Twitter button, the Twitter page opens, but I get the following error:
WHOA there!!! This page is no longer valid.it looks like someone already used the token information you provide.please return to the site tht sent you to this page or try again. it was an probably an honest mistake.
-(void)twitterclick
{
SA_OAuthTwitterEngine *_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; engine.consumerKey=[[NSString alloc]init];
_engine.consumerSecret=[[NSString alloc]init];
_engine.consumerKey = #"App consumer key";
_engine.consumerSecret = #"App Consumer secret";
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
if (controller)
[self presentModalViewController:controller animated:YES];
}
How might I resolve this?
I had the same problem... it turned out to be related to the system time on my device.
Not sure how it happened.. but after changing the date, it worked.
your trying to use OAuthData that's too old for use(expired)
in MGTwitterEngine.m look for
`#endif
_secureConnection = YES;
_clearsCookies = NO;`
and change _clearsCookies=YES;
then at the start of your 'twitterClick' put [self clearsCookies]; then the rest of your code
-(void)twitterclick {
[self clearsCookies]; SA_OAuthTwitterEngine *_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; engine.consumerKey=[[NSString alloc]init]; _engine.consumerSecret=[[NSString alloc]init]; _engine.consumerKey = #"App consumer key"; _engine.consumerSecret = #"App Consumer secret"; UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self]; if (controller) [self presentModalViewController:controller animated:YES]; }
Just put [_engine setClearsCookies:TRUE] when you are reseting the _engine variable and it should work. That is how I got it to work for me!

problem with intergating facebook session

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.

FBLoginDialog not shown

I'm an iphone newb. I added the following code to my viewDidLoad() method but a blank screen shows up. What am I doing wrong?
FBSession *session = [FBSession
sessionForApplication:#"a31c3e53bba4a5f2b3955d6e5e 876717"
secret:#"6ecbefa3807406bd13187297e58efae9" delegate:self];
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];
Thanks!
I put the code into the AppDelegate's didFinishLaunchingWithOptions method and it worked!
the call to [dialog show] has to occur on the main thread (as all UI related calls)

Adding the Facebook Like Button in an iPhone App

Does anyone know how I would include a facbeook "like button" in an iphone app. I tried calling the iframe inside of a UIWebView but that doesn't work.
Check out this nice bit of code:
http://angelolloqui.blogspot.com/2010/11/facebook-like-button-on-ios.html
Add the FBLikeButton class to your view:
FBLikeButton *likeButton = [[FBLikeButton alloc] initWithFrame:CGRectMake(0, 372, 320, 44)
andUrl:#"http://www.facebook.com/pages/De-Zilk/108209735867960"];
Thanks a lot Angel GarcĂ­a Olloqui
EDIT: Nice to add... For bonus points:
If you use above method the webpage is not well formatted for an iPhone. What you can do is run some JavaScript code to remove all the disturbing divs. Use this (long sentence):
[_webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"javascript:document.getElementsByClassName('uiButton')[2].style.visibility='hidden';var child1 = document.getElementById('standard_status');var parent1 = document.getElementById('login_form');parent1.removeChild(child1);var child2 = document.getElementById('pageheader');var parent2 = document.getElementById('booklet');parent2.removeChild(child2);document.getElementById('loginform').style.width = '200px';var child3 = document.getElementById('reg_btn_link');var parent3 = document.getElementsByClassName('register_link')[0];parent3.removeChild(child3);var child4 = document.getElementById('signup_area');var parent4 = document.getElementById('login_form');parent4.removeChild(child4);var child5 = document.getElementsByClassName('mbm')[0];var parent5 = document.getElementById('loginform');parent5.removeChild(child5);var child6 = document.getElementsByClassName('reset_password form_row')[0];var parent6 = document.getElementById('loginform');parent6.removeChild(child6);var child7 = document.getElementsByClassName('persistent')[0];var parent7 = document.getElementById('loginform');parent7.removeChild(child7);"]];
You can place it in the delegate method webViewDidFinishLoad from the FBDialog Facebook class.
Fb like Widget can be embedded in our application. You just have to add a webView and get the Fb Like Widget html code/URL here.
in ViewController.h where you want to add fb like button:
#import <UIKit/UIKit.h>
#interface TestViewController : UIViewController <UIWebViewDelegate>
#property (strong, nonatomic) UIWebView * fbLikeWebView;
-(void)embedFBLikeButton;
#end
in TestViewController.m
#import "AboutUsViewController.h"
#implementation AboutUsViewController
#synthesize fbLikeWebView = _fbLikeWebView;
- (void)viewDidLoad
{
[super viewDidLoad];
//Add this code for FbLike Webview
self.fbLikeWebView = [[UIWebView alloc] initWithFrame: CGRectMake(100.0, 50.0, 55.0, 70.0)];
_fbLikeWebView.opaque = NO;
_fbLikeWebView.backgroundColor = [UIColor clearColor];
_fbLikeWebView.delegate = self;
[self.view addSubview:_fbLikeWebView];
for (UIScrollView *subview in _fbLikeWebView.subviews)
{
if ([subview isKindOfClass:[UIScrollView class]]) {
subview.scrollEnabled = NO;
subview.bounces = NO;
}
}
}
then in ViewWillAppear method call the enbeddFBLikeButton Method to add the fbLike button wigdet on web view:
-(void)viewWillAppear:(BOOL)animated
{
[self embedFBLikeButton];
[_fbLikeWebView reload];
}
-(void)embedFBLikeButton
{
NSString *facebookUrl = //here paste the url you get from fb developer link above;
[self.fbLikeWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:facebookUrl]]];
}
You conform to UIWebViewDelegate now its turn to defining th edelegate method here:
#pragma mark - WebView Delgate Methods
- (BOOL)webView:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.lastPathComponent isEqualToString:#"login.php"])
{
[self login];
return NO;
}
return YES;
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[_fbLikeWebView stopLoading];
}
This method for login the user to facebook Account:
- (void)login
{
[FBSession setActiveSession: [[FBSession alloc] initWithPermissions:#[#"publish_actions", #"publish_stream", #"user_photos"]]];
[[FBSession activeSession] openWithBehavior: FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
switch (status) {
case FBSessionStateOpen:
// call the legacy session delegate
//Now the session is open do corresponding UI changes
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
if (!my) {
NSLog(#"Facebook error:\n%#", error.description);
[[[UIAlertView alloc] initWithTitle: #"Error"
message: #"Facebook Login error."
delegate: self
cancelButtonTitle: #"Ok"
otherButtonTitles: nil, nil] show];
return;
}
}];
[_fbLikeWebView reload];
[[[UIAlertView alloc] initWithTitle: #""
message: #"Successfully Login. Please click on like button"
delegate: self
cancelButtonTitle: #"Ok"
otherButtonTitles: nil, nil] show];
}
break;
case FBSessionStateClosedLoginFailed:
{
[_fbLikeWebView reload];
}
break;
default:
break; // so we do nothing in response to those state transitions
}
}];
}
It is an old question, but we just got the answer
By using fb sdk now we can simply add the like button
FBLikeControl *likeButton = [[FBLikeControl alloc] init];
like.objectID = #"http://ihackthati.wordpress.com/photo1/";
[self addSubview:like];
https://developers.facebook.com/docs/ios/like-button/
Several of the solutions above (e.g. #floorjiann, #fabiobeta, #Stephen-Darlington, #scott) assume that the iPhone application is also a Facebook application (with its own id).
However if your iPhone application just has a fan page, this is not the case.
You can include it in a UIWebView, just make sure it's inside <html><body>. The problem is that once the user clicks the button, the UIWebView may redirect to a log-in form, so you would have to make it large enough to fit that thing.
Have fun creating a design that presents the button in a sensible fashion.
maybe this is helpful
http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app
Facebook have recently updated their iPhone Facebook Connect framework to work with the Graph API. This is the API that you need to "Like" objects on Facebook.
Here you go - w the source code...enjoy -and please leave a comment if its useful.
http://nowbranded.com/blog/adding-a-facebook-like-button-to-an-iphone-application/
First check your authentication on Facebook, then use url code instead of iFrame like this:
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2FRemtechConfessionChambers&width=200&height=80&colorscheme=light&layout=standard&action=like&show_faces=true&send=false"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webViewFb loadRequest:req];
You can use the open source SOOMLA Profile plugin:
https://github.com/soomla/ios-profile
There are code examples there for lots of Facebook related actions (login, like, share status, upload image, get contacts, invite, etc.). See:
https://github.com/soomla/ios-profile/blob/master/SoomlaiOSProfileExample/SoomlaiOSProfileExample/ViewController.m
I this moment in time you can't. The mobile APIs are not exposing this capability.
You can use some workaround consisting in embedding the html way of doing it in your app.
Some details on the workaround here: http://petersteinberger.com/2010/06/add-facebook-like-button-with-facebook-connect-iphone-sdk/