objective-c - 如何在Voip App中使用带有背景的pushkit

标签 objective-c apple-push-notifications pushkit

目前,对于处于后台模式的我的 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];
    }];

}

最佳答案

如果你想在终止状态下运行你的应用程序并了解来电并进行进一步处理,那么你应该使用推送套件静默通知。 (这样 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

关于objective-c - 如何在Voip App中使用带有背景的pushkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44302087/

相关文章:

iPhone:如何覆盖导航 Controller 中的后退按钮?

ios - 随机错过一次点击

ios - 如何在发布版本中使用 APS 开发证书?

ios - linphone-iOS CallKit 在后台崩溃

ios - 我可以为 System UIFont 设置 ascender 或 descender 吗?

spring-mvc - JavAPNS 在本地运行但在 Centos 上不运行

xamarin.ios - Azure 通知中心和 Apple APNS 推送通知取消注册设备

ios - PushKit Xcode 9.2 问题 : Not able to get device token

ios - 如果应用程序从后台被杀死,则不会收到 Pushkit 通知

ios - 静音时播放iOS声音