【问题标题】:didUpdatePushCredentials is never called in ios 10.2在 ios 10.2 中从未调用 didUpdatePushCredentials
【发布时间】:2017-06-19 17:19:23
【问题描述】:

所以我打电话给:

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

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

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

【问题讨论】:

    标签: ios objective-c voip ios10.2


    【解决方案1】:

    参考 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
    

    Code for ObjectiveC

    Reference

    【讨论】:

    • 它对你有用吗?如果是,那么您可以接受答案。
    • 并非如此。正如我上面提到的,就我而言,通知不仅仅在 iOs 10.2 中有效。你有一些 ios 10.2 特定的代码行吗?如果可以,请您参考一下吗?
    • 使用 Pushkit,iOS 10.2 没有什么特别之处,我建议您使用 github.com/hasyapanchasara/PushKit_SilentPushNotification 交叉验证您的代码
    • 谢谢。是的,我的代码和你的很相似。但是,仍然不能仅与 iOs 10.2 一起使用。好像有什么问题。
    • 您是否下载了我的代码并按照 iOS 10.2 中的 PHP 文件发送 Pushkit 有效负载,如果这有效,那么您的代码有问题,那么您可以按照我的方式重写您的代码,您也可以检查一下您的应用程序在终止模式下崩溃,我也在 github.com/hasyapanchasara/PushKit_SilentPushNotification 上为此写了一些东西
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多