iOS设备未收到Urban Airship iOS推送通知

时间:2013-02-07 21:55:30

标签: ios push-notification apple-push-notifications urbanairship.com

我试图设置Urban Airship,以便在没有运气的情况下向我的iOS应用程序发送推送通知。

以下是我的事情:

  • 启用了推送通知的开发人员配置文件
  • 在设备上推送通知证书并上传至Urban Airship
  • 任何地方都没有错误 - UA的错误控制台为空,我检查了我的设备令牌是否处于活动状态

以下是我的AppDelegate.m文件中的一些片段

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
//Push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];


    //Init Airship launch options
    NSMutableDictionary *takeOffOptions = [[NSMutableDictionary alloc] init];
    [takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];

    // Create Airship singleton that's used to talk to Urban Airship servers.
    // Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
    [UAirship takeOff:takeOffOptions];

    // Register for notifications
    [[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                          UIRemoteNotificationTypeSound |
                                          UIRemoteNotificationTypeAlert)];

    [UAirship setLogging:YES];
}

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    // Updates the device token and registers the token with UA
    NSLog(@"APN device token: %@", devToken);
    [[UAPush shared] registerDeviceToken:devToken];
}

当我通过UA的“测试推送通知”选项卡发送通知或通过终端发送CURL命令时,未调用以下任何方法

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

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"Received push notification with userInfo:%@", userInfo);
}
- (void)handleNotification:(NSDictionary *)notification applicationState:(UIApplicationState)state
{
    NSLog(@"Received push notification with notification:%@", notification);
}

我尝试在应用关闭时发送测试推送通知,iOS也没有做任何事情。我检查了iPhone上的设置并转到了我的应用程序,它显示了徽章和横幅的推送。我在iPhone 5上运行iOS 6.1。

1 个答案:

答案 0 :(得分:3)

我明白了 - 我一定错过了文档中的这一行:

[[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
                   applicationState:application.applicationState];