2012-03-28 21 views
0

我使用此代碼從我的應用程序撥打電話(我使用webview因爲通話結束後,我不想顯示撥號應用程序):我的應用程序沒有響應一段時間後,從應用程序(使用webview)完成的phonecall

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]; 
     }  
    }  
} 

我需要調用完成並控制後顯示alertview被returend到我的應用程序,但有時需要一些時間時結束通話被檢測到,我的應用程序在此期間保持不響應荒漠化問題。

你有什麼想法該怎麼做?

回答

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 2012-03-28 16:44:49

+0

首先看看:http://developer.apple.com/library/ios/#DOCUMENTATION/NetworkingInternet/Reference/CoreTelephonyFrameworkReference/_index.html#//apple_ref/doc/uid/TP40009603 – Badre 2012-03-28 17:05:56

+0

是的,我正在使用核心電話檢測到呼叫結束。 – DixieFlatline 2012-03-28 17:08:20