【问题标题】:Not receiving push form Urban Airship on iOS在 iOS 上未收到 Urban Airship 的推送
【发布时间】:2016-10-18 01:52:55
【问题描述】:

我正在尝试让我的 iOS 设备再次接收推送通知,但它并没有真正奏效。


我工作的环境:

我的项目设置

  • 需要支持的平台:iOS8+
  • 我正在使用的UA版本:8.0.1(使用Cocoapods安装)
  • 后台模式(远程通知)和推送通知已开启

我的代码

  • 向应用程序委托添加了didReceiveRemoteNotification::√
  • 为 iOS10 添加了UNUserNotificationCenter 支持(并实现了委托方法):√

  • 配置了UAConfig:√

  • UA起飞:√
  • UAPush 拥有所有的notificationOptions 并将userPushNotificationsEnabled 设置为YES:√

这是我的代码的一些sn-ps:

(在applicationDidFinishLaunching:

if (UNUserNotificationCenter.class) {
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge)
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              if (!error) {
                                  [[UIApplication sharedApplication] registerForRemoteNotifications];
                              } else {
                                  DLog(@"There was an error trying to request authorization for push: %@", error);
                              }
                          }];
} else {
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
                                                                         settingsForTypes:(UIUserNotificationTypeAlert
                                                                                           | UIUserNotificationTypeSound
                                                                                           | UIUserNotificationTypeBadge)
                                                                         categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

UAConfig *config = [UAConfig config];

config.inProduction = self.urbanAirshipInProduction;

if(self.urbanAirshipInProduction) {
    config.productionAppKey     = self.urbanAirshipKey;
    config.productionAppSecret  = self.urbanAirshipSecret;
} else {
    config.developmentAppKey    = self.urbanAirshipKey;
    config.developmentAppSecret = self.urbanAirshipSecret;
}

[UAirship takeOff:config];

UAPush *pusher = [UAirship push];

pusher.notificationOptions = (UANotificationOptionAlert |
                              UANotificationOptionBadge |
                              UANotificationOptionSound);
pusher.pushNotificationDelegate = self;
pusher.userPushNotificationsEnabled = YES;

使用上面的代码,我希望收到对 iOS10 的 applicationDidReceiveRemoteNotification:fetchCompletionHandler:UNUserNotificationCenterDelegate 方法的调用。

但是很可惜,它们中没有一个方法敢被调用。


我不知道为什么推送不会被推送到我的设备。我在 UA 中检查了该应用,当我搜索我的设备令牌时,InstalledOpted inBackground 都是绿色的。

iOS 8,9 和 iOS10 都会出现问题。但我不确定这是否真的是操作系统的事情。

为什么?

因为我找到了一张支持票 here 和底部的某处“aboca_ext”(只需在页面上搜索他/她的用户名)说:

大家好,我发现了我的问题,当我的应用程序启动时我正在清理我的缓存,但是在 UA 启动 sqlite db 之后,我正在删除他们的数据库。在我修复它之后,一切都按原样工作。

现在这很有趣,因为我的项目也使用 SQLCipher,我想知道这是否会产生某种冲突(即使我没有清除 任何 缓存或其他任何东西),但我m 没有看到 SQLCipher 或 UA 产生的任何错误。
另一个有趣(实际上并不那么有趣)的注释是,我认为 UA 在使用 Cocoapods 安装后实际上开始失败,但同样——我不确定这是否是问题所在。

【问题讨论】:

    标签: ios iphone urbanairship.com


    【解决方案1】:

    Urban Airship SDK 负责为您注册 UNUserNotificationCenter。您应该能够删除注册调用。我认为这不会给您带来问题,但它可能会阻止 OOTB 类别等某些功能发挥作用。

    对于推送通知事件,我建议使用 UAPush 实例上的推送委托而不是工厂方法或 UNUserNotificationCenter 进行监听。 UA 委托方法在所有操作系统版本中都被调用。希望它有助于简化您的事件处理代码。

    删除 sql lite 数据库可能会导致报告出现一些问题,但我希望 push 能够继续工作。您能否打开详细日志记录和频道注册有效负载以查看 opt_in 是否设置为 true?您可以在 UAConfig 对象上启用详细日志记录。

    【讨论】:

    • 你说得对,我使用-presentationOptionsForNotification:(来自 UAPushNotificationDelegate 协议的一种方法)让它在 iOS10 上工作。甚至没有调用其他方法。谢谢!
    • presentationOptionsForNotification: 是 iOS 10 的唯一方法。您应该在前台收到 receivedForegroundNotification:completionHandler:,在后台收到 receivedBackgroundNotification:completionHandler:(需要设置 content-avialable=1)和 @987654325 @打开通知时。
    • 是的,not 使用 UNUserNotification 方法但仅使用 UA 方法,一切正常。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多