2016-11-10 195 views
1

在我的应用程序,我有APN的以下进程收到通知:设备与苹果推送通知令牌注册,但不会从服务器

  • 注册设备在didFinishLaunchingWithOptions;
  • 接收令牌didRegisterForRemoteNotificationsWithDeviceToken;
  • 发送给我的通知服务器;
  • 我的服务器发送通知;
  • 问题:我的设备没有收到它(didReceiveRemoteNotification从未呼吁调试);

已经检查了服务器和证书上的应用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 
} 
+1

您使用Sandbox APNS服务器吗?对于调试模式,您需要使用Sandbox APNS和证书 – Lefteris

+1

[此链接](https://github.com/noodlewerk/NWPusher)可以帮助您。 – Mahesh

+1

您需要检查应用程序的环境,并按照您需要配置推送通知的环境进行配置,对于开发,您必须使用开发证书为每个文件创建,并且需要在沙盒模式下使用,而在生产中必须使用生产没有沙箱的证书。 – Rajat

回答

0

LefterisRajat是正确的,我的问题是对环境的错误的证书。