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

后端 未结 5 1370
生来不讨喜
生来不讨喜 2021-02-02 11:51

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 forg

相关标签:
5条回答
  • 2021-02-02 12:07

    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.

    0 讨论(0)
  • 2021-02-02 12:10
    #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

    0 讨论(0)
  • 2021-02-02 12:13

    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).

    0 讨论(0)
  • 2021-02-02 12:16

    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.

    0 讨论(0)
  • 2021-02-02 12:19

    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.

    0 讨论(0)
提交回复
热议问题