【问题标题】:Pushkit with Sinch VOIP not working with pushkit带有 Sinch VOIP 的 Pushkit 无法与 pushkit 一起使用
【发布时间】:2017-03-05 13:56:38
【问题描述】:

我正在尝试在我的 IOS 应用中使用 Sinch 实现 App-to-App 调用。我已经在我的 iOS 应用程序中使用 Sinch 实现了 Pushkit,但是当应用程序在后台时,推送通知不起作用。

我有两个问题。

  1. 我是否需要另一个 Web 服务将推送通知发送到我的应用程序以单独接收传入应用程序,或者 Sinch 自行处理。

  2. 如果它确实可以自行处理,那么我的代码中缺少什么。

#import "AppDelegate.h"
@interface AppDelegate ()
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

    [self handleLocalNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]];

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

    [self.push registerUserNotificationSettings];

    return YES;
 }
 - (BOOL)application:(UIApplication *)app
        openURL:(NSURL *)url
        options:(NSDictionary *)options {
    return [[GIDSignIn sharedInstance] handleURL:url
                           sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                  annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
  }

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {
    return [[GIDSignIn sharedInstance] handleURL:url
                           sourceApplication:sourceApplication
                                  annotation:annotation];
}

- (id<SINClient>)client {
   return _sinchClient;
}
-(void)clientDidFail:(id<SINClient>)client error:(NSError *)error{

   NSLog(@"fail");
}

-(void)clientDidStart:(id<SINClient>)client{

    NSLog(@"Start");
    [self voipRegistration];
}


- (void)client:(id<SINClient>)client
   logMessage:(NSString *)message
      area:(NSString *)area
    severity:(SINLogSeverity)severity
   timestamp:(NSDate *)timestamp {
// If you want all messages remove the if statement

    if (severity == SINLogSeverityCritical) {
        NSLog(@"%@", message);
    }
}

- (void)initSinchClientWithUserId:(NSString *)userId {
    if (!_sinchClient) {

        _sinchClient = [Sinch clientWithApplicationKey:@"<my-key>"
                                applicationSecret:@"<my-secret>"
                                  environmentHost:@"sandbox.sinch.com"
                                           userId:userId];

        _sinchClient.delegate = self;

        [_sinchClient setSupportCalling:YES];
        [_sinchClient startListeningOnActiveConnection];
        [_sinchClient enableManagedPushNotifications];
        [_sinchClient start];
    }
 }
 - (void)handleLocalNotification:(UILocalNotification *)notification {
    if (notification) {
        id<SINNotificationResult> result = [self.sinchClient      relayLocalNotification:notification];
        if ([result isCall] && [[result callResult] isTimedOut]) {
            UIAlertView *alert = [[UIAlertView alloc]
                                  initWithTitle:@"Missed call"
                                  message:[NSString stringWithFormat:@"Missed call from %@", [[result callResult] remoteUserId]]
                                  delegate:nil
                                  cancelButtonTitle:nil
                                  otherButtonTitles:@"OK", nil];
            [alert show];
        }
    }
}

-(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
{
    [_sinchClient registerPushNotificationData:credentials.token];
}
-(void)pushRegistry:(PKPushRegistry *)registry   didInvalidatePushTokenForType:(PKPushType)type{

     NSLog(@"invalidated");
}
-(void)pushRegistry:(PKPushRegistry *)registry   didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:  (NSString *)type
{
    //notify
    NSDictionary* dic = payload.dictionaryPayload;
    NSString* sinchinfo = [dic objectForKey:@"sin"];
    UILocalNotification* notif = [[UILocalNotification alloc] init];
    notif.alertBody = @"incoming call";
    [[UIApplication sharedApplication] presentLocalNotificationNow:notif];
    if (sinchinfo == nil)
        return;

    dispatch_async(dispatch_get_main_queue(), ^{
        [_sinchClient relayRemotePushNotificationPayload:sinchinfo];
    });
}

【问题讨论】:

  • 您是否已将 Voip 证书上传到仪表板中的 Sinch?
  • 是的,我做到了。 @cjensen
  • 检查,可能是您的应用在终止或后台模式下崩溃。
  • 不,先生,它没有崩溃。
  • @WaleedVic,我也遇到了同样的问题。当应用程序在后台时,Sinch 推送通知不起作用。你找到解决方案了吗?谢谢

标签: ios objective-c voip sinch pushkit


【解决方案1】:

如果您集成了 Pushkit 和 Sinch,那么推送通知可能无法使用 PushKit 的委托功能 - didReceiveIncomingPushWithPayload。但是您可以在 SINManagedPushDelegate 的功能上获得推送通知 - didReceiveIncomingPushWithPayload。 推送通知不会到来,但当应用程序在后台时,您可以在那里收到来电事件。如果应用在后台,您可以触发本地通知,让用户知道来电。

希望对你有所帮助。

【讨论】:

  • 因为 didReceiveIncomingPushWithPayload 问题的人在他的问题中提到了这个代表,他仍然没有收到推送
  • 当应用程序退出时仍然没有收到推送,我为您提供了一点工作,请在这个问题上帮助我,提交我,让我在这里查看 Skype id
  • SinManagedPush + CallKit 在 iOS 13 中完美运行。
  • 你的问题解决了吗,谁能帮帮我,我将不胜感激
  • @MeetIosDeveloper,你有什么问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-06
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多