【问题标题】:VOIP Sinch in iOS 11 not work in backgroundiOS 11 中的 VOIP Sinch 无法在后台运行
【发布时间】:2018-04-04 20:14:41
【问题描述】:

我在 iOS 11.1.2 中使用 Sinch VOIP 在 App-To-App 之间进行通话
当应用程序状态为前台但在后台并终止时运行良好,在我打开应用程序控制台打印后没有发生任何事情

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 我的代码是

  1. 在 didFinishLaunchingWithOptions 中设置 Push Manager 和 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];


    }
    }
  1. 获取设备令牌
- (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];
}
  1. 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 不为空。
感谢您的帮助。

【问题讨论】:

    标签: ios objective-c ios11 sinch pushkit


    【解决方案1】:

    当您使用以下代码设置 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 Sample App 制作的演示视频,未经任何调整,演示中使用的设备是运行 iOS 11 的 iPhone7,它在后台、杀死和锁屏模式下接收来电:

    Sinch CallKit Sample App Demo Video

    另外,请注意 callKit 仅适用于 VoIP 推送,您是否已将正确类型的推送证书上传到 Sinch Portal?

    【讨论】:

    • 嗨@Bo Li,你能在 iOS 13 上收到 voip 通知吗?
    • @Bo Li 也面临同样的问题
    【解决方案2】:

    当你强行杀死一个应用程序时,苹果不会唤醒应用程序进行 VoIP 推送,如果你只是在后台或重启手机,苹果会唤醒它。烦人,但那是苹果

    【讨论】:

    • 感谢您的回复,请问如何在后台模式下唤醒应用或接听电话? ,我正在使用pushKit,我只想在按下主页按钮并且应用程序状态为后台时接听电话
    • @cjensen,您的描述仅适用于 iOS 11 吗?还是适用于所有 iOS 版本?
    • @Hazoomo,请看这个答案 - stackoverflow.com/questions/42609204/…
    • @gstream79 谢谢,但没有帮助我,我会使用 Sinch!没有通知
    • @cjensen 最新示例 iOS SDK 在后台 sinchCallingPush , sinchCallKit 中不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多