【发布时间】:2013-01-21 01:47:03
【问题描述】:
我已关注这些通知中心资源,但未能成功在我的 iOS 设备上接收推送通知。
- http://msdn.microsoft.com/library/jj927169.aspx
- http://channel9.msdn.com/Blogs/Subscribe/Service-Bus-Notification-Hubs-Code-Walkthrough-iOS-Edition
我已经检查、重新检查并重新检查了我的设置:
- 创建了一个新的通知中心:myhubname
- 遵循所有证书配置步骤。
- 导出私有证书并上传到 沙盒下的通知中心,以确保使用正确的 APS 网关
- 已下载配置文件,它与我的项目的捆绑包 ID 匹配,自动检测到代码签名,并成功编译。不要使用“V2D7FJQXP”。如果您想知道,该字符串会显示在您的 App ID 中:V2D7FJQXP.com.yourcompany.yourproject
- 在物理设备上运行 - 不在模拟器下
生成推送通知的演示应用程序:
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);
}
不会产生异常或问题。修改任何命名空间、键或集线器名称都会引发异常,并且来自 Azure 的提琴手响应代码是 2xx,所以一切看起来都很好。
我看到以下代码的注册正确:
- 我接受了设备上的推送通知
- 我看到 createDefaultRegistrationWithTags 调用一次,然后在后续调用中看到存在为真。
- 没有调用 didFailToRegisterForRemoteNotificationsWithError,没关系
- 在此处的代码示例中:http://msdn.microsoft.com/library/jj927168.aspx,我已将 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 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);
}
}];
}
启动演示应用程序,然后运行 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 的重命名版本。
命令运行良好。发生了什么?
【问题讨论】:
标签: c# azure push-notification apple-push-notifications azure-notificationhub