how to prevent automatic answer of incoming call - sinch

i am following this Sinch example to design an app to app calling app: http://www.hnwatcher.com/r/1345925/Android-Use-the-Sinch-SDK-to-build-a-free-calling-app-in-30-mins and i have downloaded the sample app at github.
Everything is working fine except that the incoming call is being answered automatically. I would like the call be answered after the receiver clicks a button. How can i achive this?

When you app is notified of an incoming call then the following delegate method is called (I have copied this straight from the Sinch app to app call tutorial):
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
// For now we are just going to answer calls,
// in a normal app you would show in incoming call screen
call.delegate = self;
_call = call;
[_call answer];
}
In this tutorial the call is meant to be answered straight away so we call
[_call answer];
to answer it.
To make the call answer at the push of a button you need simply move the above line of code out of this delegate method into a button action and it will work.
- (IBAction)answerButtonPressed: (UIButton *)button {
[_call answer];
}
Adding the above will mean that when a call comes in it won't be immediately answered and when you click the button the call will be connected.
Note: Don't forget to keep a pointer to the incoming call so that you answer the call as it is coming in. We can see this happening in the receive call method:
_call = call;

Related

Why stub in cypress may not work for route called after page was loaded

I am using cypress to write tests and have a problem which doesn't appear in every test. In some cases it works and I don't know why. So...
The Problem:
I defined a route and alias for it in beforeEach:
beforeEach(function () {
cy.server()
cy.route('GET', '/favourites?funcName=columnPreset', []).as('columnPresetEmpty')
cy.visit('#/search')
})
Stub works fine if http request occured on page load.
But if I perform request responding to click event (modal dialog opens and executes http request) it just appear in commands not makred as stubbed and following cy.wait('#columnPresetEmpty') fails with request timeout.
it('does not work', function () {
cy.get('[data-test=button-gridSettings]').click()
cy.wait('#columnPresetEmpty')
})
At the same time in other tests I have almost similar functionality where request is performed just by clicking on a button, without opening new modal window. It's the only difference.
What am I doing wrong?
The issue might be cypress can not yet fully handle fetch calls. You can disable it the following way but make sure you have fetch polyfill. This will then issue XHR requests which cypress can observe.
cy.visit('#/search', {
onBeforeLoad: (win) => {
win.fetch = null
}
})
More to read here:
https://github.com/cypress-io/cypress/issues/95#issuecomment-281273126
I found the reason causing such behavior. Problem was not in a modal window itself, but code performing second request was called in promise's callback of another request. Something like:
fetch('/initData')
.then(loadView)
And loadView function executed second fetch.
So when I removed loadView from promise's callback both requests become visible for cypress.
For info, I tried it out on my search modal (in a Vue app) and it works ok.
What I did:
created a dummy file named test-get-in-modal.txt in the app's static folder
added an http.get('test-get-in-modal.txt') inside the modal code, so it only runs after the modal is open
in the spec, did a cy.server(), cy.route('GET', 'test-get-in-modal.txt', []).as('testGetInModal') in a before()
in the it() added cy.wait('#testGetInModal') which succeeded
changed to cy.route('GET', 'not-the-file-you-are-looking-for.txt'..., which failed as expected
The only difference I can see is that I cy.visit() the page prior to cy.server(), which is not the documented pattern but seems to be ok in this scenario.

NSUserNotificationCenter dismiss notification

I'm trying to use the new Mountain Lion NSUserNotificationCenter for my application (which isn't too hard actually). Posting notifications works like a charm via
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
userNotification.title = #"Some title";
userNotification.informativeText = #"Some text";
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
However, i'd like to dismiss all notifications that are on the screen once the app gains focus. E.g. like the new Messages app does it. When new messages are received in the background, notifications are shown. When the app becomes active again, these are dismissed automatically and vanish from the screen and from the Notification Center.
To replicate this, I've registered a method to the NSApplicationDidBecomeActiveNotification notification which also gets called succesfully. In there I call [NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications].
This, however, has the effect that notifications that have been collected in the Notification Center are removed while the corresponding "bubbles" that are displayed in the top right corner are still displayed.
Iterating all delivered notifications and removing them each on their own has the exactly same effect, as has using scheduleNotification instead of deliverNotification.
Am I the only one experiencing this, or am I missing something to dismiss the on-screen part and the Notification Center part of a notification programatically?
The Messages app is probably using the private NSUserNotificationCenter _removeAllDisplayedNotifications or _removeDisplayedNotification: method.
You can try to use these methods to test if this is what you are looking for. Just add this category interface to declare the methods:
#interface NSUserNotificationCenter (Private)
- (void)_removeAllDisplayedNotifications;
- (void)_removeDisplayedNotification:(NSUserNotification *)notification;
#end
Unfortunately, since these are undocumented methods, you can not use them in an app distributed through the App Store. If this is indeed what you are looking for, then you should file a bug and ask for these methods to become part of the public API.
As of 10.9, the following methods remove any displayed notifications:
// Clear a delivered notification from the notification center. If the
// notification is not in the delivered list, nothing happens.
- (void)removeDeliveredNotification:(NSUserNotification *)notification;
// Clear all delivered notifications for this application from the
// notification center.
- (void)removeAllDeliveredNotifications;
The behavior seems to have changed since 10.8, as any displayed notifications are removed as well when these methods are called (thanks #0xced for clarification).
removeDeliveredNotification is removing the displayed notification for me (on 10.11), the caveat being the identifier on the notification must be set.

What's the correct way to listen for a Google+ Hangout state change?

The Hangout API at https://developers.google.com/+/hangouts/writing includes an example to set a callback function when the hangout state has changed, like this:
gapi.hangout.onStateChanged.add(onStateChange);
When run, this results in an error similar to "gapi.hangout.onStateChanged is undefined". A quick check in Firebug shows that the onStateChanged method belongs to gapi.hangout.data not gapi.hangout.
What is the correct way to add a callback function when the state has changed?
The method that you're looking for is indeed a member of gapi.hangout.data. The writing article you mention seems to be out of date. I fix it :)
To do something when state changes just attach a callback:
gapi.hangout.data.onStateChanged.add(function() {
console.log(gapi.hangout.data.getState());
});
You can find working examples of the code in action on the sample apps page.

Cocoa WebView On Navigate?

I am working on a Cocoa WebView based browser application.
Basically, I would like to have it so when the user navigates to a url, for example:
http://a/b.php, by clicking on a link on the previous page of a website, my application intercepts the "on navigate" event and changes the URL to http://a/b.php?enableapi=1
Any ideas??
Thanks in advance.
You need to assign an object as the web view's WebPolicyDelegate and implement the webView:decidePolicyForNavigationAction:request:frame:decisionListener: method.
In that method, you must call one of the WebPolicyDecisionListener protocol methods on the object that is passed as the decisionlistener parameter to the method. The three WebPolicyDecisionListener protocol methods are ignore, use or download.
You can then pass ignore to the listener and handle the link some other way for those links you're interested in intercepting.

Windows Phone App crashes when using NavigationService.GoBack() too soon

Even though NavigationService.CanGoBack returns True, NavigationService.GoBack() throws me these exceptions :
A first chance exception of type 'System.ArgumentException' occurred in System.Windows.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in
This happens systematically on two case, while the third works fine :
Crashes if I call NavigationService.GoBack() in OnNavigatedTo()
Crashes If I call NavigationService.GoBack() as a result of WebException thrown in my HTTPWebRequest when Internet is not available [1]
Works fine if Internet is available and I call NavigationService.GoBack() when my HTTPWebRequest got results, parsed them, and displayed them.
My theory is that I can't call GoBack() too soon after navigating from a page to another... My question : How can I programatically go back up the navigation stack when an HTTPWebRequest fails to load ?
Edit : I've decided to do it another way, but I think my problems might be due to navigation animations and the Windows Phone C# Toolkit (I use Feb 2011 edition)
[1] Details of my code on case 2 :
I have a simple HTTPWebRequest. My callback does this, and my app crashes when in Airplane Mode. The line NavigationService.GoBack() is responsible, even though NavigationService.CanGoBack returns true.
try
{
response = request.EndGetResponse(result);
}
catch (WebException)
{
Dispatcher.BeginInvoke(() =>
{
NavigationService.GoBack();
});
}
I tried using Deployment.Current.Dispatcher.BeginInvoke() also.
You could try using WebClient client = new WebClient();, then use client.DownloadStringAsync(new Uri("request_url")); to make your request and subscribe to the client.DownloadStringCompleted event to receive your data when the request is completed. After parsing the data, in the event handler you can then call NavigationService.GoBack(); or go to whichever page you want.
Also, if you try to do something in the OnNavigatedTo event and run into trouble you could try using the OnNavigatingFrom instead (on the previous page ofc), cancel the navigation e.Cancel = true;, do your thing as in make the request and stuff, then get the application frame and navigate to e.Uri (basically continuing the navigation you previously cancelled).
Altho this second might represent a solution as well, I think the first one is better as it does all the work async thus not blocking your UI thread. This is what I generally use in my apps. Hope it helps.

Resources