Invoke calls from background?
I'm trying to extend my current app(internal company phonebook) to be able to forward calls via our carrier's switchboard. The process is person a calls me. I can then "park" the call and call another coworker and again call the number 4 to connect person a and the coworker. But when going through the code process in my head I came to realise it might not be possible. Because what happends is Person A call, i open my app and select a person. The app initiates a call and then the app is suspended to background mode.
How would I proceed to have the app (while suspended) initiate a third call to number 4 without having to activate the app again? From my tests I can see the app sending out debug stuff but when trying to do UI stuff such as for example opening a browser, it won't pass. Also is it even possible when there is an active call? Or does the call take activity and supress all apps?
Just hoping for some quick input on this before I go ahead and spend useless hours on this realising it might not even be possible.
EDIT: Added some code examples.
First the user presses a row in the contact book.
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
Console.WriteLine("Initiate Call to Contact");
NSUrl url = new NSUrl("tel:" + _items.Contacts[indexPath.Row].Number);
if (!UIApplication.SharedApplication.OpenUrl(url))
{
var av = new UIAlertView("Not supported"
, "Scheme 'tel:' is not supported on this device"
, null
, "Ok thanks"
, null);
av.Show();
}
}
which will prompt the user to call this number (because afaik u cannot initiate the call without the prompting?
Now when this is done a timer starts (settings based) to initiate a 3rd call to number 4. This is the number the phone company switchboard uses to pair phonecalls together.
We put the app in internal state 3(intented app suspension due to outgoing call)
public partial class AppDelegate : UIApplicationDelegate
{
int ourTask;
public override void DidEnterBackground (UIApplication application)
{
Console.WriteLine("Entered Background!");
ourTask = application.BeginBackgroundTask(delegate {
if(ourTask != 0) {
application.EndBackgroundTask(ourTask);
ourTask = 0;
}
});
new System.Action(delegate {
if(_state == 3) {
BeginInvokeOnMainThread( delegate {
Console.WriteLine("Code queued");
if(UIDevice.CurrentDevice.IsMultitaskingSupported) {
Thread.Sleep(10000);
NSUrl url = new NSUrl("tel:" + 4);
if (!UIApplication.SharedApplication.OpenUrl(url))
{
Console.WriteLine("Not supported!");
}
Console.WriteLine("Invoke Finished!");
}
application.BeginInvokeOnMainThread(delegate {
if(ourTask != 0) {
application.EndBackgroundTask(ourTask);
ourTask = 0;
Console.WriteLine("App Ended!");
开发者_如何学Python }
});
});
}
}).BeginInvoke(null,null);
}
}
Not sure if I understand your problem correctly. But in general, all UI thread calls must be done on the UI thread (main thread of the app). If you have a worker thread, you have to delegate the UI calls to the UI thread, failing to do that leads to the effect that it seems that the call is ignored (well in fact, it is being ignored :)).
To call a UI thread from any other thread use the InvokeOnMainThread function. This is a method implemented on all NSObject derived classes.
this.InvokeOnMainThread (delegate { // do your stuff here} );
Hope this helps.
This was unsolvable with the current iOS structure.
精彩评论