使用 Azure 通知中心未在 iOS 上接收推送通知 - 未调用 didReceiveRemoteNotification [英] Not receiving push notification on iOS with Azure Notification Hub- didReceiveRemoteNotification is not called

查看:26
本文介绍了使用 Azure 通知中心未在 iOS 上接收推送通知 - 未调用 didReceiveRemoteNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已关注这些通知中心资源,但未能在我的 iOS 设备上成功接收推送通知.

  • ,我已将 sb://替换为 https://,否则会抛出异常.我想的不是问题

:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {NSString* connectionString = [SBConnectionString stringWithEndpoint:@"https://gift-ns.servicebus.windows.net/" listenAccessSecret:@"...snip"];self.hub = [[SBNotificationHub alloc] initWithConnectionString:connectionString notificationHubPath:@"gift-usw-dev"];[self.hub refreshRegistrationsWithDeviceToken:deviceToken 完成:^(NSError* 错误) {如果(错误 == 零){[self.hub defaultRegistrationExistsWithCompletion:^(BOOL 存在,NSError* error2) {如果(错误 2 == 零){如果(!存在){[self.hub createDefaultRegistrationWithTags:nil completion:^(NSError* error3) {如果(错误 3 != 零){NSLog(@"创建默认注册时出错:%@", error3);}}];}} 别的 {NSLog(@"获取默认注册时出错:%@", error2);}}];} 别的 {NSLog(@"刷新设备令牌出错:%@", error);}}];}

启动演示应用程序后,然后运行 ​​iOS 应用程序,这是我不知道如何有效阅读的结果仪表板.

认为我的证书不正确,或者在 Azure 和 APS 之间丢失了某些东西,我深入研究了 APS 服务的故障排除并发现了这个:http://developer.apple.com/library/ios/#technotes/tn2265/_index.html 并跳转到 部分连接到推送服务的问题

然后运行这个命令:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile server-ca-cert.pem

但是我没有 .pem 文件 (OSX),所以我找到了这个命令来获取它们:

openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

其中 keyStore.pfx 是从钥匙串导出的用于推送通知证书的 .p12 的重命名版本.

命令运行良好.发生了什么?

解决方案

AppleNotificationJsonBuilder 未使用最新的 Service Bus 预览功能 nuget 正确序列化有效负载.

因此,根据 msdn 说明中的示例:

var iosPayload = AppleNotificationJsonBuilder.Create("Hello!");iosPayload.C​​ustomFields.Add("inAppNotification", "你好!");Console.Log(iosPayload.ToJsonString());

生成:

{"aps":{"alert":"这是一个测试"},"inAppNotification":你好!这是一个测试}

格式不正确.格式正确的是字符串"

{"aps":{"alert":"这是一个测试"},"inAppNotification":"你好!这是一个测试"}

根据 http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html

一种解决方案是使用 Json.NET,或者 ping Microsoft 内部的某个人.

未解决的问题:

  • 如何监控 iOS 设备上的网络流量?
  • JSON"是否到达设备,但解析不正确?还是在 APS 中被杀死?
  • Azure 通知中心仪表板没有太大帮助

希望这可以为某人节省下午的时间.

I've followed these Notification Hub resources and have not been successful in receiving push notifications on my iOS device.

I've checked, rechecked, and rechecked my setup:

  1. Created a new notification hub: myhubname
  2. Followed all the certificate provisioning steps.
  3. Exported the private cert and uploaded to Notification Hub under Sandbox to ensure correct APS gateway is used
  4. Downloaded the provisioning profile, which matches the bundle id for my project, auto detected for code signing, and compiles succesfully. Do NOT use the 'V2D7FJQXP.' of this string that shows up in your App ID if you are wondering: V2D7FJQXP.com.yourcompany.yourproject
  5. Running on physical device - not under simulator

A demo application that is generating push notifications:

while (true)
{
    string connectionString = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessSecretWithFullAccess("myhubname-ns", "…snip");
    var hubClient = NotificationHubClient.CreateClientFromConnectionString(connectionString, "myhubname");
    var iosPayload = AppleNotificationJsonBuilder.Create("Hello!");
    iosPayload.CustomFields.Add("inAppNotification", "Hello!");
    hubClient.SendAppleNativeNotification(iosPayload.ToJsonString());

    Console.WriteLine("Sent");

    Thread.Sleep(20000);
}

No exceptions or issues are generated. Mangling any of the namespace, keys or hub names causes exceptions to be thrown, and fiddler response code from Azure is 2xx so all looks well.

I see registration occur correctly per code below:

  • I accepted push notifications on the device
  • I see the createDefaultRegistrationWithTags call once, then see that exists is true on subsequent calls.
  • No calls to didFailToRegisterForRemoteNotificationsWithError, which is OK
  • In the code example here: http://msdn.microsoft.com/library/jj927168.aspx, I have replaced sb:// with https://, as it would throw otherwise. Non-issue I'm thinking

:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {
NSString* connectionString = [SBConnectionString stringWithEndpoint:@"https://gift-ns.servicebus.windows.net/" listenAccessSecret:@"…snip"];
self.hub = [[SBNotificationHub alloc] initWithConnectionString:connectionString notificationHubPath:@"gift-usw-dev"];
[self.hub refreshRegistrationsWithDeviceToken:deviceToken completion:^(NSError* error) {
    if (error == nil) {
        [self.hub defaultRegistrationExistsWithCompletion:^(BOOL exists, NSError* error2) {
            if (error2 == nil) {
                if (!exists) {
                    [self.hub createDefaultRegistrationWithTags:nil completion:^(NSError* error3) {
                        if (error3 != nil) {
                            NSLog(@"Error creating default registration: %@", error3);
                        }
                    }];
                }
            } else {
                NSLog(@"Error retrieving default registration: %@", error2);
            }
        }];
    } else {
        NSLog(@"Error refreshing device token: %@", error);
    }
}];
}

After starting the demo app, then running the iOS application, here is the resultant dashboard which I have no idea how to read effectively.

Thinking that my certificates were not correct, or something was lost between Azure and APS, I dug into troubleshooting the APS service and found this: http://developer.apple.com/library/ios/#technotes/tn2265/_index.html and jumped to the section Problems Connecting to the Push Service

And ran this command:

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile server-ca-cert.pem

But I didn't have a .pem file (OSX), so I found this command to get them:

openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

where keyStore.pfx was the renamed version of the .p12 exported from the Keychain for the push notification cert.

The command ran fine. What is happening?

解决方案

The AppleNotificationJsonBuilder does not serialize the payload correctly using the latest nuget of Service Bus preview features.

So, per the examples from msdn instructions:

var iosPayload = AppleNotificationJsonBuilder.Create("Hello!");
iosPayload.CustomFields.Add("inAppNotification", "Hello!");
Console.Log(iosPayload.ToJsonString());

Generates:

{"aps":{"alert":"This is a test"},"inAppNotification":Hello! This is a test}

Which is malformed. Well formed is "string"

{"aps":{"alert":"This is a test"},"inAppNotification":"Hello! This is a test"}

Custom payloads are fine per http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html

One solution is to use Json.NET, or ping someone internally at Microsoft.

Open issues:

  • How could I have monitored network traffic off the iOS device?
  • Did the 'JSON' reach the device, but parse incorrectly? Or was it killed in the APS?
  • Azure Notification Hub dashboard did not help much

Hopefully this saves someone their afternoon.

这篇关于使用 Azure 通知中心未在 iOS 上接收推送通知 - 未调用 didReceiveRemoteNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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