0

所以我打电话给:

self.pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

它适用于 ios 9、10.0.2 和 10.3。调用了 didUpdatePushCredentials 并且一切正常。但是对于 ios 10.2,它永远不会被调用,并且整个 voip 功能不起作用。你能告诉它有什么问题吗?

PS:IP 语音和远程通知功能已设置。

4

1 回答 1

0

参考 ObjectiveC 代码进行 pushkit 集成

AppDelegate.h

#import <UIKit/UIKit.h>
#import <PushKit/PushKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,PKPushRegistryDelegate>
{
    PKPushRegistry *pushRegistry;
}

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m

#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

ObjectiveC 的代码

参考

于 2017-06-19T09:19:23.903 回答