【问题标题】:Urban Airship iOS Push Notifications Not Received By iOS DeviceiOS 设备未收到 Urban Airship iOS 推送通知
【发布时间】:2013-02-07 21:55:29
【问题描述】:

我尝试设置 Urban Airship 以向我的 iOS 应用程序发送推送通知,但没有成功。

这是我拥有的东西:

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

这是我的 AppDelegate.m 文件中的一些 sn-ps

- (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。

【问题讨论】:

  • 从您的描述中,不清楚是否调用了didRegisterForRemoteNotificationsWithDeviceToken
  • 是的,它正在被调用,我在 UA 的网站上看到了我的设备的设备令牌。
  • 好吧,在那种情况下,我能想到的唯一问题是证书。你应该上传正确的证书吗?您使用的是沙盒还是生产证书?您的应用程序是否使用开发或临时/生产配置文件签名?如果配置文件与证书不匹配,Apple 不会发送任何错误指示。
  • 我从苹果的 Provisioning Portal 上传了用于签署应用程序的 AppID(具有相同的捆绑 ID)的开发推送 SSL 证书。我使用开发配置文件和开发推送证书。还有其他想法吗?

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


【解决方案1】:

我想通了 - 我一定错过了文档中的这一行:

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

【讨论】:

  • Gr8。我也错过了。为你 +1。为我节省了很多时间。
  • 很高兴它有帮助。我发誓我已经阅读了 10 次文档并且看不到我的失败。我花了两天的时间才发现我错过了 1 行哈哈。
  • 请像最新的 SDK 一样更新这个答案,无论是修改还是删除
  • 嗨@AbhishekThapliyal 你能写另一个答案吗?我实际上不再从事这个项目,但我敢打赌你的回答会对未来的观众有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
相关资源
最近更新 更多