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

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

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

这是我的东西:

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

这是我的 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 上的设置并转到我的应用程序,它显示已为角标(Badge)和横幅启用推送。我在 iPhone 5 上运行 iOS 6.1。

最佳答案

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

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

关于ios - iOS 设备未收到 Urban Airship iOS 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761755/

相关文章:

apple-push-notifications - iOS 13是否具有获取设备通知 token 的新方法?

iphone - -JSONValue 失败。错误是 : Unexpected end of input

ios - 应用程序关闭且没有崩溃警报

ios - 解析检查用户是否已经点击按钮

ios - 解析推送通知 iOS

java - Android工作室: cant recieve push messages on sdk < 26 when app is on foreground

swift - 如何在 OneSignal Swift 中显示特定的 ViewController

ios - 如何根据 iOS 版本处理推送通知?

ios - iOS Notification Service Extension 会从设备中删除附加文件吗?

ios - 是否可以在 PFImageView 中为新加载的图像设置动画?与 parse.com 相关的 PFImageView