Apple push notifications 无法在iphone上从Azure通知中心接收推送通知
我已经使用Azure通知中心创建了一个带有推送通知的iphone应用程序。但我很难让工作顺利进行Apple push notifications 无法在iphone上从Azure通知中心接收推送通知,apple-push-notifications,azure-notificationhub,Apple Push Notifications,Azure Notificationhub,我已经使用Azure通知中心创建了一个带有推送通知的iphone应用程序。但我很难让工作顺利进行 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /******** code for Push notification **********/ UIUserNotificationSettings *set
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/******** code for Push notification **********/
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
NSLog(@"Entered appDelegate didFinishLaunchingWithOptions");
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken {
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:@"<my azure listening connection string>" notificationHubPath:@"myhub"];
NSLog(@" DeviceToken: %@",deviceToken);
[hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
if (error != nil) {
NSLog(@"Error registering for notifications: %@", error);
}
else {
[self MessageBox:@"Registration Status" message:@"Registered"];
}
}];
}
-(void)MessageBox:(NSString *)title message:(NSString *)messageText {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:messageText delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
NSLog(@"%@", userInfo);
[self MessageBox:@"Notification" message:[[userInfo objectForKey:@"aps"] valueForKey:@"alert"]];
}
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
/********推送通知代码**********/
UIUserNotificationSettings*设置=[UIUserNotificationSettings设置类型:UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge类别:nil];
[[UIApplication sharedApplication]注册表通知设置:设置];
[[UIApplication sharedApplication]注册表项的删除];
NSLog(@“Entered appDelegate didFinishLaunchingWithOptions”);
返回YES;
}
-(无效)应用程序:(UIApplication*)应用程序DIdRegisterForRemotionTificationswithDeviceToken:(NSData*)deviceToken{
SBNotificationHub*hub=[[SBNotificationHub alloc]initWithConnectionString:@“notificationHubPath:@“myhub”];
NSLog(@“DeviceToken:%@”,DeviceToken);
[集线器寄存器活动WithDeviceToken:deviceToken标记:无完成:^(N错误*错误){
如果(错误!=nil){
NSLog(@“注册通知时出错:%@”,错误);
}
否则{
[自我信息框:@“注册状态”信息:@“已注册”];
}
}];
}
-(无效)消息框:(NSString*)标题消息:(NSString*)消息文本{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:title消息:messageText委托:自取消按钮:@“确定”其他按钮:nil];
[警报显示];
}
-(无效)应用程序:(UIApplication*)应用程序DidReceiveMemotentification:(NSDictionary*)用户信息{
NSLog(@“%@”,userInfo);
[自我消息框:@“通知”消息:[[userInfo objectForKey:@“aps”]valueForKey:@“警报”];
}
我遵循了本文档中的步骤:
我已经在会员中心创建了一个明确的应用程序id,它与我的捆绑包id匹配。我正在使用开发者证书,并在Azure下选择了“沙盒”
当我第一次在iphone上启动我的应用程序(不是模拟器)时,我得到接受推送通知的提示——我选择了是。然后,我的代码从苹果获得一个令牌,并将其注册到Azure NH,这是成功的
从Azure NH调试选项卡,我做了一次广播发送,该发送成功地从Azure发送到APNS。但我从未收到任何通知。以下是Azure上推送通知消息的正文:
{“aps”:{“警报”:“通知中心测试通知”}
我已经尝试过多次,甚至创建了一个单独的项目来测试推送通知(单独的证书、配置文件等),但它仍然不起作用
当我故意对推送消息的有效负载进行错误格式化时,我确实收到了预期的错误,因此从NH到APNS的连接似乎是良好的
我的要求是每月发送大约1亿次推送
如果有人将Azure通知用于推送通知,请建议如何修复此问题
如果有人对Azure NH的体验不佳,请分享您最终迁移到的内容
提前谢谢。我能够让它工作 我删除了Apple developer center和mac上的所有证书。我重新创建了证书,然后再次执行该过程。这次一切都解决了
谢谢。我能让它工作了 我删除了Apple developer center和mac上的所有证书。我重新创建了证书,然后再次执行该过程。这次一切都解决了 谢谢