我使用Sinch VOIP在iOS 11.1.2中的App-To-App之间进行 call
当应用程序状态为前台但在后台运行并且终止时,效果很好,打开应用程序控制台打印后没有任何反应

Pubnub request SCHEDULED (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44, URL=https://rebtelsdk.pubnub.com/subscribe/sub-c-c5e52f20-d446-11e3-b488-02ee2ddab7fe/5e1e1309-136a-40d4-935f-2627ebe4e8f2B/0/0, NST-VoIP: NO)


Pubnub request STARTED (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44)
Pubnub request SUCCESS (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44):
(
        (
    ),
    15117251992031337
)

onPubSubSubscriptionSuccess: userInfo: {
    channel = "5e1e1309-136a-40d4-935f-2627ebe4e8f2B";
    subscribeSequence = 1;
    timetoken = 0;
    useVoIPNetworkServiceType = 0;
}

我将VOIP和APNS证书上传到Sinch仪表板,并使用SINManagedPushPushKit我的代码是


  • 在didFinishLaunchingWithOptions中设置推送管理器和SINClient

  •     self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
        self.push.delegate = self;
        [self.push setDesiredPushTypeAutomatically];
        void (^onUserDidLogin)(NSString *) = ^(NSString *userId) {
        [self.push registerUserNotificationSettings];
        [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);
         }];
    
    
         - (void)initSinchClientWithUserId:(NSString *)userId {
        if (!_client) {
        _client = [Sinch clientWithApplicationKey:@"APP-Key"
                                applicationSecret:@"APP-Secret"
                                  environmentHost:@"sandbox.sinch.com"
                                           userId:userId];
    
        _client.delegate = self;
        _client.callClient.delegate = self;
        [_client setSupportCalling:YES];
        [_client enableManagedPushNotifications];
    
        [_client start];
        [_client startListeningOnActiveConnection];
        _callKitProvider = [[SINCallKitProvider alloc] initWithClient:_client];
    
    
        }
        }
    


  • 获取设备 token

  • - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
    
    
    [self.push application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
    }
    
    -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
    NSLog(@"User Info : %@",notification.request.content.userInfo);
    completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
    
    [self.push application:[UIApplication sharedApplication] didReceiveRemoteNotification:notification.request.content.userInfo];
    }
    
    
    -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
    NSLog(@"User Info : %@",response.notification.request.content.userInfo);
    completionHandler();
    [self.push application:[UIApplication sharedApplication] didReceiveRemoteNotification:response.notification.request.content.userInfo];
    }
    
    
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [self.push application:application didReceiveRemoteNotification:userInfo];
    }
    


  • PushKit

  • -(void)voipRegistration
    {
    PKPushRegistry* voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
    voipRegistry.delegate = self;
    voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
    }
    
     -(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
    {
    
    [_client registerPushNotificationData:credentials.token];
     }
     -(void)pushRegistry:(PKPushRegistry *)registry   didInvalidatePushTokenForType:(PKPushType)type{
    
    
    NSLog(@"invalidated");
    
     }
    

    4.当SINClient启动时调用voipRegistration
    - (void)clientDidStart:(id<SINClient>)client {
    NSLog(@"Sinch client started successfully (version: %@)", [Sinch version]);
    [self voipRegistration];
    }
    

    5,实现SINManagedPushDelegate和SINCallClientDelegate
    - (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
    
    UIViewController *top = self.window.rootViewController;
    while (top.presentedViewController) {
        top = top.presentedViewController;
    }
    [top performSegueWithIdentifier:@"callView" sender:call];
    }
    
    - (SINLocalNotification *)client:(id<SINClient>)client localNotificationForIncomingCall:(id<SINCall>)call {
    SINLocalNotification *notification = [[SINLocalNotification alloc] init];
    NSArray * ansAr = @[@"رد",@"Answer"];
    NSArray * MsgAr = @[[NSString stringWithFormat:@"مكالمة لم يرد عليها من %@", [call remoteUserId]],[NSString stringWithFormat:@"Incoming call from %@", [call remoteUserId]]];
    notification.alertAction = ansAr[self.languageID];
    notification.alertBody = MsgAr[self.languageID];
    return notification;
    }
    - (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
    
    [self.callKitProvider reportNewIncomingCall:call];
    }
    

    这些是代码,如果我忘记了任何内容,请帮助我。
    我检查了credentials.token不为null。
    感谢您的帮助。

    最佳答案

    使用以下代码设置Sinch管理的推送时:

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

    Sinch SDK将自动为您注册所有PushKit。因此,描述中的第3步和第4步不是必需的,也不应该在那里。也不需要步骤2中的部分代码。请从SDK下载包中查看Sinch CallKit示例应用程序,并参考该应用程序的实现。

    以下是使用3.12.4 Sinch SDK CallKit示例应用程序制作的演示视频,没有进行任何调整,该演示中使用的设备是运行iOS 11的iPhone7,它将在后台,中止和锁屏模式下接收来电:

    Sinch CallKit Sample App Demo Video

    另外,请注意callKit仅适用于VoIP推送,您是否已将正确类型的推送证书上载到Sinch Portal? ios - iOS 11中的VOIP Sinch在后台无法运行-LMLPHP

    关于ios - iOS 11中的VOIP Sinch在后台无法运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47500782/

    10-08 23:39