2012-03-28 7 views
0

私のアプリからこのコードで電話します(私はwebviewを使用します)。アプリから作られたphonecallが完了したあと、iphoneアプリが応答しない

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

私は、通知に加入して通話の終了を検出:

私は私のアプリにreturendされ、コールが終了し、制御後alertviewを表示する必要がありますが、
[[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]; 
     }  
    }  
} 

は、時にはそれがいくつかの時間がかかるときの終わりコールは通知で検出され、このアプリケーションでは私のアプリケーションは応答しなくなりますリオード。

あなたは何をすべきか考えていますか?

答えて

0

通知による通話終了の検出は正しいです。私は何をしなければならなかったことは、コールが終了した(ので、コマンドは、メインスレッドで実行)した後、この行を追加することです:

dispatch_async(dispatch_get_main_queue(), ^{ 
       [self showAlert]; 
      }); 
0
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 
+0

は、私は私のアプリにダイヤラアプリから通話終了とiOSが戻った後alertviewを表示する必要があります。 – DixieFlatline

+0

最初に見てください:http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Reference/CoreTelephonyFrameworkReference/_index.html#//apple_ref/doc/uid/TP40009603 – Badre

+0

はい、コアテレフォニーを使用しています呼の終了を検出する。 – DixieFlatline

関連する問題