iPhone, call another phone number in response to the first not answering?

久未见 提交于 2019-12-20 09:52:02

问题


I am attempting to create an application that will initiate a call to a priority 1 contact on a call-center-like list.

Then, if that contact does not answer (let's forget the whole problem of answering machines here), I'd like to call the priority 2 contact, and so on, until one of them answers or I exhaust my list.

Is this possible?

I've tried the following:

  1. Hook into the CTCallCenter.CallEventHandler event, and checking the call state for CTCallStateConnected and CTCallStateDisconnected, and I get it to respond to the fact that the call disconnected, without ever connecting, and then attempt to initiate another call like I did the first, but this second attempt just sits dead in the water.
  2. Override the DidEnterBackground method, and periodically check the CTCall.CallState property, basically again trying to respond to a disconnect that was never connected, but this does not appear to work either

I also tried adding a short delay (1 second, 2.5 seconds and 10 seconds) after detecting the disconnected state before attempting the next dial, to allow for the phone application to "settle down" after aborting the call, this did not change anything.


回答1:


I'm of the opinion that this is better solved at the destination of the phone call. I would either have the phone company configure a "follow me" service, use Twilio or some other 3rd party service (as already suggested), or configure my own PBX using something like Asterisk (Asterisk includes the ability to configure "follow me" type behavior). It provides you much more flexibility and control, even if you did find a way to do this natively in iOS.

Having said that, I did get this to work in iOS assuming the following:

  1. Your app initiates the call.
  2. The phone app is opened, dials the number, and disconnects.
  3. The user explicitly returns to your app. If you managed to get the events while your app was backgrounded, I want to know more :-).
  4. On return of control to your app, the phone events are sent and a new call is initiated.

I have the following snippet of code in my UIApplicationDelegate didFinishLaunchingWithOptions method:

// In appdelegate header, ct is declared as @property (strong, nonatomic) CTCallCenter *ct; 
self.ct = [[CTCallCenter alloc] init];
self.ct.callEventHandler = ^(CTCall *call) {
    if (call.callState == CTCallStateConnected) {
        // do some state management to track the call
    } else if (call.callState == CTCallStateDisconnected) {
        // check that this is the expected call and setup the
        // new phone number
        NSURL *telURL = [NSURL URLWithString:myNewNumberURL];
        [application openURL:telURL];    
    }     
};

This will make the new call. I'm using the iOS 5 SDK; tested on an iPhone 4s.

EDIT:

Using Return to app behavior after phone call different in native code than UIWebView as a starting point, I've managed to get this to work. Note that I have punted on memory management for clarity. Assuming you use the web view technique for getting back to your app after the call is complete, try something like this in the call completed block:

else if (call.callState == CTCallStateDisconnected) {
    // check that this is the expected call and setup the
    // new phone number
    NSURL *telURL = [NSURL URLWithString:myNewNumberURL];
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWebView *callWebview = [[UIWebView alloc] init]  ;
        [self.window.rootViewController.view addSubview:callWebview];
        [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]]; 
        // and now callWebView sits around until the app is killed....so don't follow this to the letter.  
    });
}

However, this may not quite give you what you want either. The user will get an alert on each call request, providing an opportunity to cancel the call.




回答2:


You could use http://labs.twilio.com/twimlets/findme. You could have the app call a Twilio number and it could use findme to call all the numbers in order.




回答3:


I didn't take a deeper look at it, but the Deutsche Telekom SDK might contain what you're looking after:

http://www.developergarden.com/fileadmin/microsites/ApiProject/Dokumente/Dokumentation/ObjectiveC-SDK-2.0/en/interface_voice_call_service.html

I really am not sure though (don't have time to really look at it at the moment) - I just remembered I'd read somewhere that they have an iOS SDK that is supposed to also handle call management, so I'm posting the link here for you to find out (and hopefully tell us if it works).




回答4:


#pragma mark -
#pragma mark Call Handler Notification
-(void)notificationCallHandler {

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callReceived:) name:CTCallStateIncoming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callEnded:) name:CTCallStateDisconnected object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(callConnected:) name:CTCallStateConnected object:nil];

}
-(void)callEnded:(NSNotification*)notification {
     NSLog(@"callEnded");

}

-(void)callReceived:(NSNotification*)notification {
     NSLog(@"callReceived");
}
-(void)callConnected:(NSNotification*)notification {
     NSLog(@"callConnected");
}

May this will help you




回答5:


if you wanna setup a new call, while app is in background, i dont see any proper way for this, a lil hack could be, getting location update (because u can get location updates while app is in background), and location service automatically wakes up your application when new location data arrives, and small amount of time is given to application in which u can execute some code, in that time you may start a new call.

u can read further here:
search this ''Starting the Significant-Change Location Service'' in this link Location Aware programming guide , and read the paragraph that is written after the code block.



来源:https://stackoverflow.com/questions/8717780/iphone-call-another-phone-number-in-response-to-the-first-not-answering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!