Facebook app invite delegation mixup - ios

I'm sending a Facebook app-invite from my iOS app, and am trying to implement a success/fail flow using blocks.
I have created a class to wrap my communication with the Facebook SDK which exposes a send invite method.
In that method, I have the following code:
[self.facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
as explained in the documentation.
My wrapper class conforms to the FBDialogDelegate protocol, and I have implemented 5 of the delegate methods:
dialog:(FBDialog *)dialog didFailWithError:(NSError *)error,
dialogCompleteWithUrl:(NSURL *)url,
dialogDidComplete:(FBDialog *)dialog,
dialogDidNotCompleteWithUrl:(NSURL *)url
dialogDidNotComplete:(FBDialog *)dialog
The problem is that wether the user cancels the dialog or sends the request, the only method that is being called is the dialogCompleteWithUrl:(NSURL *)url method.
Can anyone explain this?

This seems to be an outstanding issue that has been reported several times. The fact that didComplete is called when the user presses the cancel button is indeed a valid action so it is by design that didComplete gets called. The documentation might be outdated and we have a task to fix it, but reporting a doc bug on our developer site will allow you to track the progress.
So to answer your question, if the user presses the 'x' button it should call didNotComplete. User pressing send or cancel will call didComplete as it is designed that way.
However, this person came up with a good workaround for FBDialog where you can probably do something similar, such as checking the value of the URL when it succeeded vs when the user presses cancel and have an if check that checks for that case.
Hope this helps.

Related

Call Facebook login and then press home button to get back

I have the following problem, I would like to know if there is something implemented by facebook or if you know a workflow to avoid this issue.
Basically I use facebook SDK to login, the app send me to the browser, and instead of clicking cancel or Accept/OK, I click home button and get back to the app.
In that case I don't receive any callback from facebook SDK.
Also, facebook have a delay when you click cancel or ok button, so when you get back to the app you don't know exactly if you are going to receive the callback or not by 2-3 seconds aprox.
My current solution is giving a delay of 3-4 seconds and check if you are already connected or not, and show the buttons again if you are not connected. It's a really bad approach, but I can't find something better for that.
You're supposed to handle this in your AppDelegate's applicationDidBecomeActive method:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Handles activation with regards to returning from iOS 6.0 authorization dialog or from fast app switching
[FBSession.activeSession handleDidBecomeActive];
}
Docs here: https://developers.facebook.com/docs/reference/ios/current/class/FBSession/#handleDidBecomeActive
and
https://developers.facebook.com/docs/ios/ios-sdk-tutorial/authenticate/

How to automatic confirm a call in telpromt confirm call alertview

im trying to make a call through the telpromt command:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://123456789"]];
The problem is, that when de code is run, it displays an UIAlertView not of my property, asking to confirm the call.
It has to buttons: Cancel and Call.
I want to programatically press the call button in the AlertView.
Is it possible ?
Thanks !
iOS does this to protect the user from malicious applications which would try to make random calls. Anytime there are integrations to the phone, SMS, twitter, facebook, etc. apple requires the user to accept and allow the application to perform the action. This is why the iPhone displays a UIAlertView asking the user wether they really want to make a call to the phone number you're providing.

fbDidLogin did not called at first time in iOS. So I modified, is this the right process?

My fbDidLogin delegate method didn't called at first time. I searched and found "fbDidLogin not called" and "IOS - Facebook SDK fbDidLogin not called — initialize view controllers" and handled the facebook url into my Application Delegate correctly. But fbDidLogin method didn't called. So I searched again. Someone says in "Problems with fbDidLogin never called iOS" to change
[self authorizeWithFBAppAuth:YES safariAuth:YES];
into
[self authorizeWithFBAppAuth:NO safariAuth:YES];
in my Facebook.m file. After doing that my facebook login view just changed, yet couldn't get what I need. In that situation what I did? I added a line
[facebook logout:self];
right after
[facebook authorize:permissions];
Because I thought there is a problem in login or/and logout syncronisation, so if I call facebook logout method it might (yes, MIGHT) work.Voila! it does work, at least for me.Now all I want to ask you, is there any problem or logical error in my process? And is there a better way to do so?

In which situation are those Facebook IOS FBSessionDelegate methods called?

It's clear to me that these are called upon login if a user grants or denials permission:
- (void)fbDidLogin;
- (void)fbDidNotLogin:(BOOL)cancelled;
But i was wondering when the following FBSessionDelegate methods could be called:
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt;
- (void)fbDidLogout;
- (void)fbSessionInvalidated;
The documentation says:
//Called after the access token was extended.
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt;
//Called when the user logged out.
- (void)fbDidLogout;
//Called when the current session has expired.
- (void)fbSessionInvalidated;
Now when would such a thing happen? When i call the following?
[Facebook authorize:nil];
There is no chance i will get a fbDidLogout call back right?
Maybe if a user removes my app from his Facebook account via the Facebook app, would this method be called than? No, because my app doesn't open in that case..
...so in which situation would these be called?
I think i found it myself...
This one:
- (void)fbDidExtendToken:(NSString*)accessToken expiresAt:(NSDate*)expiresAt;
Could be called when you call:
[facebook extendAccessTokenIfNeeded];
This one:
- (void) fbDidLogout;
Gets called when you call
[facebook logout] //(of course..)
The last one:
- (void)fbSessionInvalidated;
Get's called when you try to send a http request to Facebook with an expired session token.
I found it in the Facebook SDK header file Facebook.m
I'll leave the question here for anyone looking for the answer :)

Wrong Twitter result after unsuccessful send attempt

When using TWTweetComposeViewController in IOS5 to compose and send a Tweet, if the Tweet is a duplicate, an error alert is shown saying that the Tweet is duplicate and cannot be sent, but the TWTweetComposeViewControllerCompletionHandler still gets a result value of TWTweetComposeViewControllerResultDone rather than TWTweetComposeViewControllerResultCancelled.
(This may happen in other cases as well, not just for duplicate tweets - I didn't check).
This makes it impossible to show a confirmation message to the user after a successful send, because the handler gets the same "Done" result whether the send was successful or not.
Is there another way to check whether the send was actually successful?
The documentation for TWTweetComposeViewController's completionHandler states the following:
The handler has a single parameter that indicates whether the user finished or cancelled composing the tweet.
The completionhandler tells you whether the user actually finished or cancelled composing the tweet herself, regardless of the result of actually posting the tweet.
Update
I've looked a bit further into this and it seems like the TWTweetComposeViewController is one of those convenience classes that take away most of the work for the developer in exchange for not letting the developer handle anything by himself. In this case, the developer has no way of handling the errors that occur when sending the tweet and has to rely on the iOS provided alert dialogs to inform the user instead.
You can hack around this by using Saleh's method, though I don't consider that safe enough to use in an actual app. See the comments in his answer.
Another method is by implementing your own view controller which handles tweet composition and sending. You can do this by following the procedure in the following stackoverflow answer.
Check for the alert message, if the alert message is shown you'll be able to know that the error occurred. I think that the alert message gets added in the window. You can check the count of window's subviews, if they get increased when delegate function is called, you'll know that the error occurred.
Isn't it only a view controller? The result of the view controller is fine as it states what happened with the view controller ( it is done running ).
With what are you sending your tweet? That library most likely has some stuff implemented you can use to determine whether your tweet was sent successfully or not.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if([urlResponse statusCode]==200)
{
//Tweet tweeted successfully....
}
}
this might help you .
In respponse if url response code is 200 you can say text is tweeted....

Resources