【发布时间】: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 中检查了该应用,当我搜索我的设备令牌时,Installed、Opted in 和 Background 都是绿色的。
iOS 8,9 和 iOS10 都会出现问题。但我不确定这是否真的是操作系统的事情。
为什么?
因为我找到了一张支持票 here 和底部的某处“aboca_ext”(只需在页面上搜索他/她的用户名)说:
大家好,我发现了我的问题,当我的应用程序启动时我正在清理我的缓存,但是在 UA 启动 sqlite db 之后,我正在删除他们的数据库。在我修复它之后,一切都按原样工作。
现在这很有趣,因为我的项目也使用 SQLCipher,我想知道这是否会产生某种冲突(即使我没有清除 任何 缓存或其他任何东西),但我m 没有看到 SQLCipher 或 UA 产生的任何错误。
另一个有趣(实际上并不那么有趣)的注释是,我认为 UA 在使用 Cocoapods 安装后实际上开始失败,但同样——我不确定这是否是问题所在。
【问题讨论】:
标签: ios iphone urbanairship.com