ios - 在 iOS 上未收到推送形式的 Urban Airship

标签 ios iphone urbanairship.com

我正在尝试让我的 iOS 设备再次接收推送通知,但效果并不理想。


我的工作环境:

我的项目设置

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

我的代码

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

  • 配置了UAConfig:√

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

以下是我的代码的一些片段:

(在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 中检查了该应用,当我搜索设备 token 时,已安装选择加入背景均为绿色。

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

为什么?

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

Hi guys, I found my problem, I was cleaning up my cache when my application was starting, but after UA initiated sqlite db, and by this I was deleting their db. After I fixed that, everything worked as it should.

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

最佳答案

Urban Airship SDK 负责为您在 UNUserNotificationCenter 中注册。您应该能够删除注册调用。我认为这不会给您带来问题,但它可能会阻止某些功能(例如 OOTB 类别)运行。

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

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

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

相关文章:

iphone - 需要传递什么值?http ://maps. google.com/maps/geo?q=%@&output=csv

ios - Urban Airship 在 iOS 上的实现

ios - 具有购物 list 功能的食谱应用程序的数据库设计(iOS CoreData)

ios - 将 CUSTOM 元数据保存在从 iOS 中的 AVFoundation 获取的图像中

ios - TableView 编辑模式不会为单元格添加动画

ios - Testflight 无法加载应用程序

iphone - 在观看时将 HTTP 直播视频录制到文件?

ios - 更改 NavigationBar 人字形和标题颜色无效

android - Prolem 使用 urbanairship Provider android

android - 接收但不显示 GCM 推送通知