我刚刚将 Xcode 更新到版本 8.3.3 并且 pushRegistry:didUpdatePushCredentials:forType:
不再被调用。
在这个新版本的 Xcode 中,与 PushKit 相关的东西是否发生了变化?
这是我的注册代码:
_voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
_voipRegistry.delegate = self;
_voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
最佳答案
带有 pushkit 的 Xcode 版本 8.3.3 没有变化。从 2.2 到 3.X,swift 语言的语法级别发生了变化,但 Objective C 没有任何变化。(我看到你的代码在 Objective C 中)
我建议一旦你可以交叉验证你的代码。
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");
}
希望对你有帮助。
关于ios - 不再调用 didUpdatePushCredentials [Xcode 8.3.3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44769235/