IOS关于极光推送JPush不能上报deviceToken的问题

问题一、 ld:library not found for -ljpush-ios-3.0.9
clang: error: linker command failed with exit code 1 (use -v to see invocation)

问题二、JIGUANGDeviceTokenController Not get deviceToken yet. Maybe: your certificate not configured APNs? or current network is not so good so APNs registration failed? or there is no APNs register code? Please refer to JPush docs.

由于项目比较老,推送的SDK版本比较低的原因,之前老的项目可以正常推送,现在在旧项目基础上新改版的一个app不能正常推送,推送账号一切都是正常的。

解决问题一

查询了相关的网上解决办法

  • 一、在Build Settings 中的 Library Search Paths 中手动添加其路径。

  • 二、在Build Phases 中的 Link Binary With Libraries删除重新添加,有的说是物理路径删除了,引用的路径还在,会出现红色文件缺失,在这儿我根本没有找到对应的.a文件。然后我重新添加上去也根本没有效果。

  • 三、已经使用了CocoaPods更新到jpush-ios-3.1.2,开始的时候出现了两个,引用路径只有一个,删除了以前的3.0.9的版本,重新添加,一样的无效。

最后查找到一个方法说在 "xxxx".xcodeproj 文件显示包内容,打开以文本显示。然后比如你缺失的一个 SDK 或者 .a文件名称在里面全局搜索到所有引用到这个文件的地方然后在替换成前面报的错的地方的文件名称 ljpush-ios-3.0.9 换成 ljpush-ios-3.1.2

注意:这儿修改如过害怕修改配置错误,你可以先备份一份。因为这个修改错误项目有的会打不开。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
MARKETING_VERSION = 1.5.5;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-l\"GZCQRCodeManager\"",
"-l\"c++\"",
"-l\"jcore-ios-2.1.8\"",
"-l\"jpush-ios-3.0.9\"",
->这儿换成你需要的 "jpush-ios-3.1.2"
"-l\"resolv\"",
"-l\"z\"",
"-framework",
"\"Bugly\"",
"-framework",
修改了过后重新 clean build floder一下,然后重新运行。是不是已经可以编译通过了。

这儿多说一点点,就是在SVN提交代码的时候,难免会冲突。有时候开发项目,是其他同事一起修改然后提交了造成的小的冲突问题不大,有时候直接修改一下就能编译通过了。但是有时候严重的时候直接项目都打不开了情况下。

也是同样的原理直接打开上面”xxxx”.xcodeproj文件搜索

  • 粘贴这个符号--- 搜索出来的地方,删除乱码。
  • 符号--->搜索出来的地方,删除乱码。
  • 符号<---搜索出来的地方,删除乱码。
这个处理过后在保存应该就可以正常打开项目了

解决问题二

1
2
3
4
5
6
7
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[JPUSHService registerDeviceToken:deviceToken];//注册设备token
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error);
}

这儿这两个方法都直接没有进入,但是之前在3.1.2的版本在另外一个项目中可以推送,是另外一个同事负责的。所以我一直觉得应该代码没什么问题,是不是在注册通知的时候版本不同造成的于是修改了以下代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*向APNs注册,获取deviceToken用于推送*/
-(void)registerAPNS:(UIApplication *)application{
float systemVersionNum = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersionNum >= 10.0) {
// iOS 10 notifications
_notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
// 创建category,并注册到通知中心
[self createCustomNotificationCategory];

_notificationCenter.delegate = self;
// 请求推送权限
[_notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
// granted
NSLog(@"User authored notification.");
// 向APNs注册,获取deviceToken
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
});
} else {
// not granted
NSLog(@"User denied notification.");
}
}];
} else if (systemVersionNum >= 8.0) {
// iOS 8 Notifications
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
[application registerUserNotificationSettings:
[UIUserNotificationSettings settingsForTypes:
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
categories:nil]];
[application registerForRemoteNotifications];
#pragma clang diagnostic pop
} else {
// iOS < 8 Notifications
#pragma clang diagnostic push
#pragma clang diagnostic ignored"-Wdeprecated-declarations"
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
#pragma clang diagnostic pop
}
}

增加了在IOS10以上设备注册通知的兼容性问题,然而在他的设备上IOS 13.1 是正常的,在我自己的设备上还是一样的不进入didRegisterForRemoteNotificationsWithDeviceToken函数。挺郁闷的既然不是这个注册的原因,然后放弃了这种修改代码的想法。

然后去网上查找到

  • 一、说有可能是其他SDK重写了AppDelegate类的方法didRegisterForRemoteNotificationsWithDeviceToken导致没有进入这个函数。但是我查找了并没有出现这个问题,所以这个排除了。

  • 二、检查通知开关是否开启(这个我压根不用怀疑),push证书entitlements文件也是有的,也排除了。

办法:

后来发现在IOS13.1以下的版本,可以进去,但是有时候会出现Not get deviceToken yet. Maybe: your certificate not configured APNs? or current network is not so good so APNs registration failed? or there is no APNs register code? Please refer to JPush docs.然后在我自己的手机设备是直接无法访问。后来去极光官网看了更新记录文档。发现

1
2
3
4
5
6
7
JPush iOS SDK v3.2.0
更新记录
根据JCore 2.0进行JPush重构,性能优化
JCore 要求版本在2.0以上
删除了setupWithOption:launchingOption 初始化接口,不再支持pushConfig.plist方式集成
优化消息状态上报逻辑
修复已知bug
看到了过后前面还有几个版本,没有怀疑直接更新了。

修改了pod 'JPush', '~> 3.2.0' 然后在 pod update 更新完过后重新运行。没错现在都会进去了 didRegisterForRemoteNotificationsWithDeviceToken 了,在测试了一下,在高版本也是正常可以推送了。

到这儿为止是不是觉得想笑了,瞎折腾,哈哈哈。