How to get callbacks for Facebook iOS SDK Like action? - ios

Trying to perform the built-in-like using the Facebook iOS SDK. I've found snippets like the one below but how can I get notified of the requests status? I have no way of knowing whether the request actually caused a Like, failed, and for what reasons.
Q: How to get callbacks from FBRequest?
// Trying to perform built-in-like
[FBRequest requestWithGraphPath:#"me/namespace:like"
parameters:#{#"recipe":#"http://myurl.com"}
HTTPMethod:#"POST"];

According to the FBRequest API the requestWithGraphPath method does not make an actual call.
//Returns a newly initialized request object that can be used to make a
//Graph API call for the active session.
requestWithGraphPath:parameters:HTTPMethod:
The call itself can be made with startWithCompletionHandler:.
- (FBRequestConnection*)startWithCompletionHandler:(FBRequestHandler)handler;
Looking at the API for FBRequestConnection, FBRequestHandler is a block that is passed to register for a callback with the results of that request once the connection completes.
In other words, it will be called when the request completes with a success, error, or cancel action.

Related

Twilio Ougoing Voice Call : Token does not allow outgoing calls on first attempt

I have recently started experiencing peculiar behaviour trying to initiate an outgoing phone call Browser -> Phone.
Every time I refresh the browser, my initial call to Twilio.Device.connect(phonecallParams) results in an error:
Received an error from the gateway: {code: 31002, connection: Connection, message: "Token does not allow outgoing calls."}.
If I make a second call to Twilio.Device.connect(phonecallParams), it works.
Also every subsequent call works. But if I refresh the browser then the first call fails again.
It used to work first time, every time. But I last tested this weeks ago.
Now it fails first time, every time.
With the first, failed call:
I get call my back-end to get a token
I return the token to the JS method
I call Twilio.Device.connect(phonecallParams)
I get the error message.
Nothing else happens. There is no attempt to call my TwiML handler.
With the second, successful call:
I get call my back-end to get a token
I return the token to the JS method
I call Twilio.Device.connect(phonecallParams)
My backend method that handles TwiML is called
Call is initiated.
In both cases:
the token construction is identical the same method which creates the token the same way (and includes new OutgoingClientScope(_twilioAccount.TwiMLApplicationSid))
the phonecallParams are identical
Would anyone have a clue as to what could be going on??
Ok, so this turned out to be one of those silly things...
I was calling Twilio.Device.connect() immediately / too soon after requesting my token - the same trigger that requested the token also triggered Twilio.Device.connect().
I now request my outgoing phone token when my page loads, and by the time the user wants to initiate the call the token has been completely set up, wherever it needs to be.

Can React-Native's Native side request information from React? (Bridging/Native Modules)

TLDR: Is there some way I can use a callback or get a return value from react to my native code (iOS)? Or can I use a set of locks to enforce ordering for eventdispatcher and eventemitter listeners to enforce an ordering?
More Information:
So I'm using the event dispatcher in my iOS code (self.bridge.eventDispatcher) and that's working great. I'm able to send events with information to my react code.
However, I noticed that this works asynchronously. I currently use this because if I require information on my iOS side, I send a ping to my react side requesting this information. I then lock upon the request and wait for my react code to use NativeModules and invoke an iOS method where I get the requested data.
Basically, enforcing a synchronous pattern feels a little dangerous because I'm not sure whether bridging methods can fail. For example, I can send an event to react and then lock. If my react side does not get it, or fails to send a notification to the iOS side, then I will never unlock and then will have deadlock. So to this, I have two questions. Is bridging reliable enough to avoid deadlocking through this method? Or is there a better way to accomplish the same result and request information from my react side from my iOS code?
Awesome so I got it, turns out there's a structure called RCTResponseSenderBlock. I made another
iOS method:
-(void)tmpMethod:(RCTResponseSenderBlock)callback{
[self.bridge.eventDispatcher sendAppEventWithName:#"channel" body:#{#"Block":callback}
] ;
}
javascriptReciever:
EventEmitter.addListener("channel", async event => {
console.log(event)
event.Block(["Hello There"]);
return;
});
ios Method Invocation:
[self tmpMethod:^(NSArray* response){
NSLog((NSString*)[response objectAtIndex:0]); //prints Hello There
}];
UPDATE
Turns out when I try to do the same for Android, I can't. The Android platform uses WriteableMap or WriteableArray to send events using the following method:
private void sendEvent(ReactContext reactContext,
String eventName,
#Nullable WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
WriteableMap and WriteableArray both do not accept objects such as callbacks which made it not possible to request information from the Javascript side. I also attempted to pass in a Promise as opposed to a WriteableMap or WriteableArray and that threw an error. To communicate asynchronously in a synchronous context for android,
I will have to send an event from native to javascript
lock twice to prevent further execution in side native
on my javascript side invoke a method on my native side once viewing the request with the requested data
unlock within the native method invoked by javascript
resume execution since the program has been unlocked
unlock once further after handling whatever needed to be handled synchronously. (Comment if you want my code implementation)
EDIT AGAIN:
The above flow didn't work. I don't have any control over threads in Android since ReactNative always uses the main thread. So if I end up locking the main thread then react-native cannot enter another method to unlock, thus I have deadlock. So not possible to enforce synchronous exchange of data with android.

ios and evernote : How can i know which Createnote failed?

I'm using Evernote sdk on iOS and it works great.
But sometimes I'm sending several CreateNote methods in a row and, as Evernote sends them asynchronously, if one of them falls in error I can't say which one ...
The CreateNote method returns a Note object when success but a NSError when failure. And this one doesn't tell about which query it was.
How can I know which note creations failed ?
Thanks
The Evernote SDK does send the requests asynchronously, but its always one request at a time. So if a request fails, its always the last request that you made.

Cannot send facebook apprequest from iOS because FBSession.activeSession.isOpen gives false

my app can only send app request during the first run that the user logins into facebook. Once the app is restarted, the app request gets stopped because FBSession.activeSession.isOpen gives false.
Although, FBSession.activeSession.isOpen gives false still the app can perform other operations such as posting to the wall, getting friend list etc. Only it cannot send app requests. And still it has a valid access token too.
Any ideas?
You say "FBSession.activeSession.isOpen gives false", but, just to be sure : when do you run this test? When your call to the login request returns, or inside the asynchronous request's callback ?
If it's done outside the request's callback, it may say that the session is not opened yet. Then, the request returns properly, which means that any further call to another FB request succeeds.
Does that help?
If it does not, maybe an overview of your code could.
Ok, next to your comment from the previous answer :
yes, that's what you said already. but WHERE in your code do you check isOpen? To expect a proper value, it should be something like this :
FBSession openActiveSessionWithReadPermissions:_readPerms allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
// here is the proper place to check the isOpen boolean, and to go on with your program, including the app request
}];
// not the proper place to check isOpen.
Does that help?

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