【问题标题】:how to use pushkit with background in Voip App如何在 Voip App 中使用带有背景的 pushkit
【发布时间】:2017-06-01 08:15:24
【问题描述】:

目前,对于处于后台模式的我的 Voip 应用程序,我使用下面的代码,当我的 voip 应用程序进入后台时或当它进入后台并在呼叫到达时锁定手机时,它会显示通知。我看到在 IOS 8 和更高版本中 setKeepAliveTimeout 不再工作了,我们需要使用 Pushkit,有没有在不编码我们的服务器端的情况下使用 pushKit?

- (void)registerKeepAliveHandler:(UIApplication*) application
{
    LogInfo(TAG_MAIN, @"Registering KeepAliveTimeout");
    [application setKeepAliveTimeout:600 handler:^{
        [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_KEEPALIVE_RECEIVED object:nil];
        NSMutableString* statusStr = [[NSMutableString alloc] init];
        switch ([[UIApplication sharedApplication] applicationState]) {
            case UIApplicationStateActive:
                [statusStr appendString:@"foreground"];
                break;
            case UIApplicationStateInactive:
                [statusStr appendString:@"inactive"];
                break;
            case UIApplicationStateBackground:
                [statusStr appendString:@"background"];
                break;
            default:
                assert(0);
                break;
        }
        LogInfo(TAG_MAIN, @"===================================== Keepalive received in %@ application status ===============================", statusStr);
        [UIApplication getIPAddress];
        LogInfo(TAG_MAIN, @"%@", [[UIDevice currentDevice] batteryInfo]);
        [[SipEngine sharedInstance] isServerReachable];
        [[SipEngine sharedInstance] isRegistered];
        [[SipEngine sharedInstance] startStopRegistration];
        [[[SipEngine sharedInstance] registration] registering];
    }];

}

【问题讨论】:

    标签: objective-c apple-push-notifications pushkit


    【解决方案1】:

    如果您想在终止状态下运行您的应用程序以了解来电并进行进一步处理,那么您应该使用 Push kit 静音通知。 (这种方式 Whatsapp 通话、Skype 等应用程序工作)

    Refer

    #import "AppDelegate.h"
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
        pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
        pushRegistry.delegate = self;
        pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
    
        return YES;
    }
    
    #define PushKit Delegate Methods
    
    - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
        if([credentials.token length] == 0) {
            NSLog(@"voip token NULL");
            return;
        }
    
        NSLog(@"PushCredentials: %@", credentials.token);
    }
    
    - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
    {
        NSLog(@"didReceiveIncomingPushWithPayload");
    }
    
    
    @end
    

    Way to schedule local notification based on puskit payload

    【讨论】:

    • 嗨@Hasya,谢谢。如果我想使用上面的函数,而不是 NSLog(@"didReceiveIncomingPushWithPayload");你知道我需要用什么吗?因为这样是行不通的。
    • 欢迎@Steven,如果我的回答对您有帮助,那么您可以投票并接受它。让我知道我是否可以随时为您提供帮助。
    • 你能接收 Pushkit 有效载荷吗?如果是,那么基于 pushkit 有效负载,您可以安排带有来电声音的本地通知,也可以添加交互事件以接受或拒绝呼叫。github.com/hasyapanchasara/PushKit_SilentPushNotification/…
    【解决方案2】:

    继续前进,必须在 iOS 中使用 Pushkit for Background (BG) Voip 应用程序,因为它将在 iOS 11 中完全弃用 Voip BG 套接字。(我认为他们已经弃用了 iOS 10 SDK 中的支持,但 iOS 10适用于 SDK 9)

    要回答您的问题,不,您需要在服务器端实现 APNS 接口以与 Apple 的 APNS 云通信,以便您的应用可以通过 Apple 接收用于 Voip 呼叫等的 VOIP 推送。另外,请注意,如果 BG 中的 VOIP 应用程序处于封闭网络(无互联网)中,它们将不再适用于 iOS,因为必须通过 APNS 接口向使用 Pushkit 的应用程序提供 Voip 推送。

    【讨论】:

    • 嗨@Ayush,我找不到任何教程如何在服务器端实现APNS接口以与Apple的APNS云对话。有没有找到一些教程如何做到这一点?
    • 这有点奇怪。苹果实际上已经提供了完整的文档。 developer.apple.com/library/content/documentation/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多