在两个具有不同包ID的不同应用之间进行VOIP通话

问题描述

我正在尝试通过两个不同的应用程序建立voip呼叫。假设一个是卖方,另一个是客户。卖方应用只能呼叫,而客户应用只能接收呼叫。我已经设置了两个应用程序,分别带有sinch applicationKey,secret,userID等。由于要在客户应用程序中接听电话,我已经在Apple Dev Account中为客户应用程序的捆绑包ID 生成了VOIP证书。而且我已将该证书(p12)上传到Sinch仪表板中。我在客户应用中使用托管推送。 但是我无法在客户应用程序中收到推送或呼叫。 我尝试更改两个应用程序的捆绑包ID。当我将两个应用程序的捆绑包ID保持相同时,它的工作原理就像魅力。 我的问题是,如何在两个具有不同包ID的不同应用之间进行voip呼叫? 这是我的AppDelegate.m文件代码,当捆绑包ID相同时,它应能正常工作:

#import "SINCallKitProvider.h"
#import "CallViewController.h"

@interface AppDelegate () <SINClientDelegate,SINCallClientDelegate,SINManagedPushDelegate>
@property (nonatomic,readwrite,strong) id<SINManagedPush> push;
@property (nonatomic,strong) SINCallKitProvider *callKitProvider;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  NSLog(@"didFinishLaunchingWithOptions:");

  [Sinch setLogCallback:^(SINLogSeverity severity,Nsstring *area,Nsstring *message,NSDate *timestamp) {
    NSLog(@"[%@] %@",area,message);
  }];

  self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
  self.push.delegate = self;
  [self.push setDesiredPushType:SINPushTypeVoIP];

  self.callKitProvider = [[SINCallKitProvider alloc] init];

  void (^onUserDidLogin)(Nsstring *) = ^(Nsstring *userId) {
    [self initSinchClientWithUserId:userId];
  };

  [[NSNotificationCenter defaultCenter]
      addobserverForName:@"UserDidLoginNotification"
                  object:nil
                   queue:nil
              usingBlock:^(NSNotification *note) {
                Nsstring *userId = note.userInfo[@"userId"];
                [[NSUserDefaults standardUserDefaults] setobject:userId forKey:@"userId"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                onUserDidLogin(userId);
              }];

  [[NSNotificationCenter defaultCenter] addobserverForName:@"UserDidlogoutNotification"
                                                    object:nil
                                                     queue:nil
                                                usingBlock:^(NSNotification *note) {
                                                  _client = nil;
                                                }];

  return YES;
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
  id<SINCall> call = [_callKitProvider currentEstablishedCall];

  // If there is one established call,show the callView of the current call when
  // the App is brought to foreground. This is mainly to handle the UI transition
  // when clicking the App icon on the lockscreen CallKit UI.
  if (call) {
    UIViewController *top = self.window.rootViewController;
    while (top.presentedViewController) {
      top = top.presentedViewController;
    }

    // When entering the application via the App button on the CallKit lockscreen,// and unlocking the device by PIN code/Touch ID,applicationWillEnterForeground:
    // will be invoked twice,and "top" will be CallViewController already after
    // the first invocation.
    if (![top isMemberOfClass:[CallViewController class]]) {
      [top performSegueWithIdentifier:@"callView" sender:call];
    }
  }
}

#pragma mark -

- (void)initSinchClientWithUserId:(Nsstring *)userId {
  if (!_client) {
    _client = [Sinch clientWithApplicationKey:@"<My key>"
                            applicationSecret:@"<My secret>"
                              environmentHost:@"clientapi.sinch.com"
                                       userId:userId];

    _client.delegate = self;
    _client.callClient.delegate = self;

    [_client setSupportCalling:YES];
    [_client enableManagedPushNotifications];

    _callKitProvider.client = _client;
    [_client start];
//      [_client startListeningOnActiveConnection];
  }
}

- (void)handleRemoteNotification:(NSDictionary *)userInfo {
  if (!_client) {
    Nsstring *userId = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
    if (userId) {
      [self initSinchClientWithUserId:userId];
    }
  }

  [self.client relayRemotePushNotification:userInfo];
}

#pragma mark - SINManagedPushDelegate

- (void)managedPush:(id<SINManagedPush>)managedPush
    didReceiveIncomingPushWithPayload:(NSDictionary *)payload
                              forType:(Nsstring *)pushType {
  NSLog(@"didReceiveIncomingPushWithPayload: %@",payload.description);

  // Since iOS 13 the application must report an incoming call to CallKit if a
  // VoIP push notification was used,and this must be done within the same run
  // loop as the push is received (i.e. GCD async dispatch must not be used).
  // See https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry .
  [self.callKitProvider didReceivePushWithPayload:payload];

  dispatch_async(dispatch_get_main_queue(),^{
    [self handleRemoteNotification:payload];
    [self.push didCompleteProcessingPushPayload:payload];
  });
}

#pragma mark - SINCallClientDelegate

- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
  // Find MainViewController and present CallViewController from it.
  UIViewController *top = self.window.rootViewController;
  while (top.presentedViewController) {
    top = top.presentedViewController;
  }
  [top performSegueWithIdentifier:@"callView" sender:call];
}

- (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
  [self.callKitProvider willReceiveIncomingCall:call];
}

#pragma mark - SINClientDelegate

- (void)clientDidStart:(id<SINClient>)client {
  NSLog(@"Sinch client started successfully (version: %@)",[Sinch version]);
}

- (void)clientDidFail:(id<SINClient>)client error:(NSError *)error {
  NSLog(@"Sinch client error: %@",[error localizedDescription]);
}

@end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)