Приложение Iphone не отвечает в течение некоторого времени после завершения телефонного звонка, сделанного из приложения (с веб-просмотром) - PullRequest
0 голосов
/ 28 марта 2012

Я звоню из своего приложения с этим кодом (я использую webview, потому что после завершения звонка я не хочу показывать приложение для набора номера):

UIWebView *callWebview = [[UIWebView alloc] init];
[self.view addSubview:callWebview];
NSURL *telURL = [NSURL URLWithString:tel];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

Я обнаруживаю завершение звонка подпиской на уведомление

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ctCallStateDidChange1:) name:@"CTCallStateDidChange" object:nil];

   - (void)ctCallStateDidChange1:(NSNotification *)notification
  {
     NSString *call = [[notification userInfo] objectForKey:@"callState"];
     if ([call isEqualToString:CTCallStateDisconnected])
    { 
       NSLog(@"Call has been disconnected");
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Obvestilo" message:@"Some text?"
                                                           delegate:self cancelButtonTitle:@"Yes" otherButtonTitles: @"No", nil];
            [alert show];
        }       
    }       
}

Мне нужно показать оповещение после завершения вызова и восстановления контроля в моем приложении, но иногда это занимает некоторое время, когда обнаруживается окончание вызова с уведомлением, и мое приложение не отвечает на запросы в течение этого периода.

У вас есть идеи, что делать?

Ответы [ 2 ]

0 голосов
/ 29 марта 2012

Обнаружение завершения вызова с уведомлениями является правильным.Мне нужно было добавить эту строку после завершения вызова (чтобы команда выполнялась в главном потоке):

 dispatch_async(dispatch_get_main_queue(), ^{ 
                [self showAlert];
            });
0 голосов
/ 28 марта 2012
please expline more your what you need exactly !!!!! after reading you code, i concluded that you want save a event handler that you notify if state of call !! No ?

First You need to save event Handler in you Apps before you make you call like that ok : 

1. `CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler = ^(CTCall* call)
{
if (call.callState == CTCallStateDisconnected)`enter code here`
{
NSLog(@"Call has been disconnected");
// you can do any things here, your treatment
}
else if (call.callState == CTCallStateConnected)
{
NSLog(@"Call has just been connected");
// you can do any things here, your treatment
}
else if(call.callState == CTCallStateIncoming)
{
NSLog(@"Call is incoming");
// you can do any things here, your treatment
}
else
{http://stackoverflow.com/posts/9911993/edit
NSLog(@"None of the conditions");
// you can do any things here, your treatment
}
}; 
`
2. you need indicated to the system that you want let you apps alive in background and make call by the code : 
`UIApplication *appDelegate = [UIApplication sharedApplication];

    if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
    {
        DLog(@"supporte Multitasking");
    }else
    {
        return;
    }`

    `backgroundTask = [appDelegate beginBackgroundTaskWithExpirationHandler:^{
        // DLog(@"beginTask");

    }];`

    `NSString *tel = [@"tel://" stringByAppendingFormat:@"12345"];
    [appDelegate openURL:[NSURL URLWithString:tel]];`


3. For returne in you application registry event UILocalNotification and implement this method in you delegate
` #pragma mark local notification
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
`
i hope that help you
...