接收者如何在 Sinch 中接听电话?

How does a receiver receive a call in Sinch?

我正在查看代码,特别是使用调用按钮启动调用的主视图控制器。两个用户在输入他们的名字后都必须在这个 View Controller 上才能在数据库中找到。

但我对被叫方如何收到呼叫通知以及它如何进入显示他们可以接听或挂断电话的呼叫视图控制器感到困惑。

我知道 prepareForSegue 将调用设置为调用者,但我仍然对之后剩下的几行感到困惑。

所以请注意最后两个委托方法:第一个委托方法执行一个 segue,这是有道理的。但是第二个呢,因为我很困惑它如何进入呼叫视图控制器,让被呼叫者接听或拒绝。

MainViewController.m

#import "MainViewController.h"
#import "CallViewController.h"

#import <Sinch/Sinch.h>

@interface MainViewController () <SINCallClientDelegate>
@end

@implementation MainViewController

- (id<SINClient>)client {
  return [(AppDelegate *)[[UIApplication sharedApplication] delegate] client];
}

- (void)awakeFromNib {
  self.client.callClient.delegate = self;
}

- (IBAction)call:(id)sender {
  if ([self.destination.text length] > 0 && [self.client isStarted]) {
    id<SINCall> call = [self.client.callClient callUserWithId:self.destination.text];
    [self performSegueWithIdentifier:@"callView" sender:call];

  }
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  CallViewController *callViewController = [segue destinationViewController];
  callViewController.call = sender;
}

#pragma mark - SINCallClientDelegate
// Outgoing Call?
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {

  [self performSegueWithIdentifier:@"callView" sender:call];
}
// Incoming Call?
- (SINLocalNotification *)client:(id<SINClient>)client localNotificationForIncomingCall:(id<SINCall>)call {
  SINLocalNotification *notification = [[SINLocalNotification alloc] init];
  notification.alertAction = @"Answer";
  notification.alertBody = [NSString stringWithFormat:@"Incoming call from %@", [call remoteUserId]];
  return notification;
}

But what about the second one because I'm confused as to how it segues into call view controller that lets the callee answer or decline

header 向您解释发生了什么:

The return value will be used by SINCallClient to schedule ... a UILocalNotification. That UILocalNotification, when triggered and taken action upon by the user, is supposed to be used in conjunction with -[SINClient relayLocalNotification:].

  • (void)client:(id)client didReceiveIncomingCall:(id)call {

    [自己执行SegueWithIdentifier:@"callView" sender:call]; }

当应用程序在前台并且来电正在进行中时被调用,它会推送 viewcontroller 来电,并且由于它的方向是来电,您将看到一个拒绝接听按钮,

  • (SINLocalNotification *)client:(id)client localNotificationForIncomingCall:(id)call { SINLocalNotification *notification = [[SINLocalNotification alloc] init]; notification.alertAction = @"Answer"; notification.alertBody = [NSString stringWithFormat:@"Incoming call from %@", [call remoteUserId]]; return通知; }

当应用程序在后台并且您已启用推送时调用