实施开发行为PushKit和测试 [英] Implement PushKit and test in development behavior

查看:2158
本文介绍了实施开发行为PushKit和测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序(VOIP应用)中实现PushKit服务,但我有以下疑问:我看到,我可以生成唯一的生产VOIP证书,它的工作原理,如果我尝试来测试开发设备VOIP推送通知服务?

i'd like to implement PushKit service within my app ( Voip app ), but i have following doubt: I see that i can generate only production voip certificate , it works if i try to test voip push notification service on develop device ?

这是我的执行测试:

通过这个3号线code的我能得到didUpdatePushCredentials回调推令牌,我用它来保存到我的服务器。

With this 3 line of code i can get push token on didUpdatePushCredentials callback that i use to save into my server.

PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

服务器端生成我只警报文本正常的有效载荷推送通知,并派我到VoIP标记存储到我的服务器。

Server side i generate a "normal" payload push notification with only alert text, and i sent to voip token stored into my server.

我用调试日志回调,但他们从来没有得到所谓的!

I use the callback with debug log, but they never getting called!

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(NSString *)type {

          NSLog(@"didInvalidatePushTokenForType");

}

-(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {

          NSLog(@"didReceiveIncomingPushWithPayload: %@", payload.description);

}

-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
     if([credentials.token length] == 0) {
           NSLog(@"voip token NULL");

          return;
     }

      NSLog(@"didUpdatePushCredentials: %@ - Type: %@", credentials.token, type);

}

如果我尝试生成从我的服务器到pviously上传的,我从来没有在didReceiveIncomingPushWithPayload回调通知VoIP设备令牌$ P $推送通知的消息,但是从服务器我得到200 OK消息(成功发送消息)

If i try to generate a push notification message from my server to voip device token previously uploaded, i'm never notified on didReceiveIncomingPushWithPayload callback, but from server i get 200 ok message( message was successfully sent )

推荐答案

万一有人有兴趣与Pushkit测试VOIP推送通知我在这里留下了一个小程序,我成功如下:

Just in case someone is interested on testing voip push notifications with Pushkit here I left a small procedure I followed successfully:

1 - 创建,如果你没有它已经,一个 CSR 钥匙扣访问和保存本地CSR

1 - Create, if you do not have it already, a CSR with Keychain Access and save your CSR locally.

2 - 转到苹果开发并获得证书,标识和放大器;配置文件。在会员中心。

2 - Go to Apple Developer and get access Certificates, Identifiers & Profiles. On the member center.


  • 在Identifiers->应用标识制作一个新的应用程序ID

  • 内部设备 - >所有添加的设备UDID要用于测试网络电话推

  • 在证书 - >所有创建一个新产品证书:VoIP的服务证书。选择previously创建的应用程序ID为你的VoIP服务证书。选择previously创建CSR(证书签名请求),并曾经创造下载新voip_services.cer

一旦下载双击 voip_services.cer 为了打开钥匙串访问应用程序和生成的证书导出私钥:右键导出 certificate.p12 文件

Once downloaded double click on voip_services.cer in order to open Keychain Access application and export private key for generated certificate: right button Export certificate.p12 file.

保存 voip_services.cer certificate.p12 文件夹中,以创建您的服务器推送通知发生器

Save voip_services.cer and certificate.p12 file in a folder in order to create your server push notification generator

最后去苹果开发人员网站再次和供应Profiles-内部>分发创建一个新的特设分布图,包括它要用于测试VOIP推动所有设备的UDID。下载此配置文件和拖放到你的X code,以使用它在你的应用程序。

Finally go to Apple Developer website again and inside Provisioning Profiles->Distribution create a new Ad-Hoc distribution profile including on it all devices UDID you want to use for testing voip pushes. Download this profile and drag and drop to your xcode in order to use it on your application.

现在,让我们创建了iOS应用程序,将收到VOIP推送通知:

Now lets create the iOS app that will receive voip push notifications:


  • 创建根据X code新项目菜单新的单一视图的应用。

  • 根据previous部分创建应用程序ID填写其包标识。

  • 添加PushKit.framework在常规 - >链接的框架和库。

  • 在功能使背景模式,选择IP语音选项。

  • 在生成设置 - > code签署选择设置你的个人资料下载previously和选择配送为code签署身份

让我们在应用程序中添加code 的帕斯夸莱在他的问题补充:

Lets add in the app the code Pasquale added in his question:

在你的根视图控制器头( ViewController.h
)为PushKit.framework进口:

In your root view controller header (ViewController.h ) an import for PushKit.framework:

#import <PushKit/PushKit.h>

添加委托,以实现其功能:

Add delegate in order to implement its functions:

@interface ViewController : UIViewController <PKPushRegistryDelegate>

添加在你的根视图控制器的viewDidLoad功能(ViewController.m)推注册:

Add in viewDidLoad function of your root view controller (ViewController.m) push registration:

- (void)viewDidLoad {
    [super viewDidLoad];

    PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
    pushRegistry.delegate = self;
    pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}

完成所需的委托功能:

Implement required delegate functions:

- (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");
}

一旦所有的编译和确定,将项目归档和导出IPA文件,以便在测试设备​​上安装它(可以使用例如Testflight做的工作)。

Once everything is compiling and ok, archive your project and export your ipa file in order to install it on testing devices (you can use for example Testflight to do the job).

执行,并从日志中获得PushCredentials我们将用于发送推送。

Execute it and get from logs the PushCredentials we will use to send pushes.

现在让我们去到服务器端(我后面的<一个这个伟大指南href=\"http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1\">raywenderlich教程):

Now lets go to server side (I followed this great guide of raywenderlich tutorials):

获取回]文件夹中放置了三个文件:

Get back to folder were you placed the three files:


  • voip_services.cer

  • certificate.p12

1 - 打开一个终端,并创建证书文件PEM文件:

1 - Open a terminal and create pem file from certificate file:

#openssl x509 -in voip_services.cer -inform der -out PushVoipCert.pem

2 - 从出口私钥文件创建PEM文件:

2 - Create pem file from exported private key file:

#openssl pkcs12 -nocerts -out PushVoipKey.pem -in certificate.p12

3 - 在一个加入两个PEM文件:

3 - Join both pem files in one:

#cat PushVoipCert.pem PushVoipKey.pem > ck.pem

Simplepush 从<脚本href=\"http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1\">raywenderlich教程教程的和修改


  • $ deviceToken通过添加PushCredentials(从应用程序日志)

  • 你加在第2步
  • $的密码创建密码时PushVoipKey.pem

就是这样。执行PHP脚本:

That's it. Execute php script:

#php simplepush.php

和你应该接受你的VoIP推送通知(你应该看到应用程序日志:didReceiveIncomingPushWithPayload)

and you should receive your voip push notification (you should see app log: "didReceiveIncomingPushWithPayload")

这是测试我不知道我怎么会接收通过pushkit框架标准的推送通知,但不幸的是我没有答案,因为注册推式时,我找不到任何其他PKPushType但PKPushTypeVoIP后...

After that test I wondered how I could receive standard push notifications through pushkit framework, but unfortunately I have no answer as when registering the push type I could not find any other PKPushType but the PKPushTypeVoIP...

pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

这就是全部!感谢您的阅读!

That's all! Thanks for reading!

这篇关于实施开发行为PushKit和测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆