设备在 Apple Push Notification 中注册了令牌,但没有收到来自服务器的通知

Posted

技术标签:

【中文标题】设备在 Apple Push Notification 中注册了令牌,但没有收到来自服务器的通知【英文标题】:Devices are registered with token in Apple Push Notification but don't receive notifications from the server 【发布时间】:2016-11-10 13:16:23 【问题描述】:

在我的应用中,我对 APN 有以下流程:

didFinishLaunchingWithOptions中注册设备; 使用didRegisterForRemoteNotificationsWithDeviceToken接收令牌; 发送到我的通知服务器; 我的服务器发送通知; 问题:我的设备没有收到它(didReceiveRemoteNotification从未调用过调试);

已经检查了服务器上的 App Id 和证书。

谁能指出我做错了什么?


AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    // Checking if app is running ios 8
    if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) 
        // Register device for iOS8
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings
                settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
                        UIUserNotificationTypeSound categories:nil];
        [application registerUserNotificationSettings:notificationSettings];
        [application registerForRemoteNotifications];
     else 
        // Register device for iOS7
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
                UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
    

    //...

    return YES;


- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 

    NSLog(@"Registration successful, bundle identifier: %@, device token: %@",
            [NSBundle.mainBundle bundleIdentifier], deviceToken);

    // Receive the token and send it to my Server


- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err 
    NSLog(@"Error in registration. Error: %@", err);


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

    // Handle notification

【问题讨论】:

您使用的是沙盒 APNS 服务器吗?对于调试模式,您需要使用沙盒 APNS 和证书 this link 可以帮助您。 您需要检查您的应用程序的环境,并根据您需要配置推送通知的环境,对于开发,您必须使用开发证书创建每个文件并且需要在沙盒模式下使用,而在生产中,您必须使用生产证书来进行 per 没有沙盒。 【参考方案1】:

Lefteris 和 Rajat 是对的,我的问题是环境证书错误。

【讨论】:

以上是关于设备在 Apple Push Notification 中注册了令牌,但没有收到来自服务器的通知的主要内容,如果未能解决你的问题,请参考以下文章

用 PHP 处理 Apple Push Notification Service 的设备令牌的方法

Apple Push Notification Service - 通知消息不会发送到 iPhone 设备

APNS Apple 推送通知令牌过时并停止工作

Apple Push Notification Service 用户响应

Apple Push Notification 在共享服务器上不起作用

某些设备的令牌无效