【问题标题】:iPhone SDK: Launching an app after call endsiPhone SDK:通话结束后启动应用程序
【发布时间】:2011-01-19 17:43:24
【问题描述】:

如何在应用内拨打电话或在通话结束后立即启动应用?我知道这是可能的,因为应用商店中的一些应用已经在这样做了。

【问题讨论】:

标签: iphone phone-call


【解决方案1】:

这是通过使用 telprompt 而不是 tel 来完成的。请看下面的代码

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:18004912200"]];

【讨论】:

    【解决方案2】:

    我从 Apple 网站获得了这段代码,它运行良好:

    -(IBAction) dialNumber:(id)sender{
    
    NSString *aPhoneNo = [@"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ; NSURL *url= [NSURL URLWithString:aPhoneNo];
     NSURL  *url= [NSURL URLWithString:aPhoneNo];
    NSString *osVersion = [[UIDevice currentDevice] systemVersion];
    
    if ([osVersion floatValue] >= 3.1) { 
    UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 
    [webview loadRequest:[NSURLRequest requestWithURL:url]]; 
    webview.hidden = YES; 
    // Assume we are in a view controller and have access to self.view 
    [self.view addSubview:webview]; 
    [webview release]; 
    } else { 
    // On 3.0 and below, dial as usual 
    [[UIApplication sharedApplication] openURL: url];
    }
    
    
    }
    

    【讨论】:

      【解决方案3】:

      我认为这有两个部分

      1. 应用程序已在运行,用户收到提示有电话打进来,并要求接受或拒绝
      2. 用户接到电话,但应用程序未运行

      在第一种情况下,您的UIApplicationDelegate 将收到消息application:willChangeStatusBarFrame:application:didChangeStatusBarFrame:applicationWillResignActive:applicationDidBecomeActive: 都可能多次收到消息,这取决于用户是否选择接听电话,并且可能是applicationWillTerminate:,如果他们选择离开你的申请。您还可以使用未注册为应用程序委托的类中的NSNotificationCenter 观察这些事件,有关详细信息,请参阅UIApplication 类参考的“通知”部分。

      在第二种情况下,我不知道官方 SDK 是否可以在电话结束时启动您的应用程序。您能否提供执行此操作的应用程序列表?

      编辑:

      我想我现在明白你的意思了。你应该听从@jessecurry 的建议,UIApplication 上的openURL 使用tel: 协议将拨打电话。至于他们声称“做不可能的事情”并且在拨打电话时不退出应用程序,我不确定他们是如何做到的,因为我没有写它。他们可能正在使用 Skype 等外部 VOIP 服务,或者只是将tel: URL 加载到不可见的网页中。这两个我都不能评论,因为我还没有尝试过。

      【讨论】:

      • 这里有几个应用程序正在这样做 1. 婴儿监视器和警报 (isarson.com/en/baby-monitor-alarm-iphone)。他们最近的一条推文-“婴儿监视器和警报现在具有无限数量的警报。是的,我们做到了不可能,当执行电话呼叫时,我们的应用程序没有退出!- 4 周 22 小时前” 2. 叫醒警报跨度>
      • 请记住,对于 3.x+,如果您确实使用 openURL,用户现在会收到提示。在 2.x 中它只会拨号
      【解决方案4】:

      如果您想在应用内拨打电话,可以使用 tel: 网址。

      这是一个将电话号码作为字符串并发起呼叫的方法。

      - (void)dialNumber: (NSString*)telNumber
      {
          // fix telNumber NSString
          NSArray* telComponents = [telNumber componentsSeparatedByCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
          telNumber = [telComponents componentsJoinedByString: @""];
      
          NSString* urlString = [NSString stringWithFormat: @"tel:%@", telNumber];
          NSURL* telURL = [NSURL URLWithString: urlString];
          //NSLog( @"Attempting to dial %@ with urlString: %@ and URL: %@", telNumber, urlString, telURL );
      
          if ( [[UIApplication sharedApplication] canOpenURL: telURL] )
          {
              [[UIApplication sharedApplication] openURL: telURL];
          }
          else
          {
              UIAlertView* alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( @"Dialer Error", @"" ) 
                                                              message: [NSString stringWithFormat: NSLocalizedString( @"There was a problem dialing %@.", @"" ), telNumber] 
                                                             delegate: nil 
                                                    cancelButtonTitle: NSLocalizedString( @"OK", @"" ) 
                                                    otherButtonTitles: nil];
              [alert show];
              [alert release];
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-24
        • 1970-01-01
        • 2011-10-29
        • 1970-01-01
        相关资源
        最近更新 更多