【问题标题】:Iphone app is not responsive for some time after phonecall made from app (with webview) finishes从应用程序(带有网络视图)拨打电话后,Iphone 应用程序在一段时间内没有响应
【发布时间】:2012-03-28 16:30:22
【问题描述】:

我使用此代码从我的应用程序拨打电话(我使用 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];
        }       
    }       
}

我需要在通话结束后显示 alertview 并将控制权返回给我的应用程序,但有时需要一些时间才能检测到通话结束并发出通知,并且我的应用程序在此期间保持无响应。

你有什么想法吗?

【问题讨论】:

    标签: iphone objective-c uiwebview nsnotifications


    【解决方案1】:
    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
    

    【讨论】:

    【解决方案2】:

    检测到带有通知的通话结束是正确的。我要做的是在调用完成后添加这一行(因此在主线程上执行的命令):

     dispatch_async(dispatch_get_main_queue(), ^{ 
                    [self showAlert];
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多