jpush / jpush-react-native

JPush's officially supported React Native plugin (Android & iOS). 极光推送官方支持的 React Native 插件(Android & iOS)。
http://docs.jiguang.cn
MIT License
1.35k stars 340 forks source link

最新版(2.9.3)通过JS不能上报APNS #887

Closed NapChen closed 2 years ago

NapChen commented 2 years ago

你的运行环境

期望效果

正确上报iOS的APNs和收到极光下发的推送

实际效果

实际上按照readme中的配置,注释AppDelegate.mm中的初始化代码后,在JS的componentDidMount方法中调用 JPush.init不能正确的上报deviceToken 如果按照在didFinishLaunchingWithOptions中初始化

[JPUSHService setupWithOption:launchOptions appKey:@"xxxxxxx" channel:@"dev" apsForProduction:YES]; JPUSHRegisterEntity entity = [[JPUSHRegisterEntity alloc] init]; if (@available(iOS 12.0, )) { entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings; } [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; // 自定义消息 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];

是能够正确的初始化并且正确的上报APNs的

但如果在JS中初始化的时候,也就是在AppDelegate.mm中注释掉上述代码后,app启动或者在JS中调用JPush.init,都不会弹出请求通知权限的弹框

image

重现步骤

根据readme即可重现

Debug logs

这是通过JS初始化时出现的日志

2022-09-02 10:23:25.417607+0800 rmc[93581:4984213] | JIGUANG | I - [JIGUANG] --------------------------- JPush Log ---------------------------- --------------------JPush SDK Version:3.7.4--build:227---------- --------------------JCore Lib Version:3.2.1--build:278---------- -----------------AppKey:xxxxxxxx----------------

2022-09-02 10:23:25.421361+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] Need to be configured in Info.plist Privacy - Tracking Usage Description 2022-09-02 10:23:25.421625+0800 rmc[93581:4984204] | JIGUANG | W - [JIGUANG] 请将JPush的初始化方法,添加到[UIApplication application: didFinishLaunchingWithOptions:]方法中,否则JPush将不能准确的统计到通知的点击数量。参考文档:https://docs.jiguang.cn/jpush/client/iOS/ios_guide_new/#_6 2022-09-02 10:23:25.423997+0800 rmc[93581:4984204] | JIGUANG | I - [JIGUANG] Action - closeConection 2022-09-02 10:23:25.424281+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] +[JPUSHHelper postNotification:withUserInfo:] name: kJPFNetworkIsConnectingNotification (null) 2022-09-02 10:23:25.424663+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] Action - isSisOnProtect 2022-09-02 10:23:25.424968+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] sis is not on protect 2022-09-02 10:23:25.455767+0800 rmc[93581:4984220] [javascript] licenseVersion = 2.0.0 2022-09-02 10:23:25.471295+0800 rmc[93581:4984213] | JIGUANG | I - [JIGUANG] Action - jpush setup 2022-09-02 10:23:25.515814+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] send udp data 2022-09-02 10:23:25.517599+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] send udp data succeed 2022-09-02 10:23:25.518255+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] udp socket begin send behavior 2022-09-02 10:23:25.518681+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] last load config timeinterval: 1662085228480.038, intervals: 86400000, still need: 86222963.596191 2022-09-02 10:23:25.518832+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] config is invalid , don't start timer 2022-09-02 10:23:25.534376+0800 rmc[93581:4984222] | JIGUANG | D - [JIGUANG] star Report LocationS trategy 2022-09-02 10:23:25.540298+0800 rmc[93581:4984222] | JIGUANG | E - [JIGUANG] operate sdk is not open, cancel event [jg_app_launch] record 2022-09-02 10:23:25.546793+0800 rmc[93581:4984212] | JIGUANG | D - [JIGUANG] httpsis, type:active_user, address list:( "https://ali-stats.jpush.cn/v3/report", "https://stats.jpush.cn/v3/report", "https://183.232.25.151:443/v3/report" ) 2022-09-02 10:23:25.580252+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] Action - parse 2022-09-02 10:23:25.588307+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] close udp socket 2022-09-02 10:23:25.691896+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] 连接主机成功 2022-09-02 10:23:25.711331+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] +[JPUSHHelper postNotification:withUserInfo:] name: kJPUSHNetworkDidSetupNotification (null) 2022-09-02 10:23:25.712801+0800 rmc[93581:4984204] | JIGUANG | D - [JIGUANG] Action - doSendTcpRequest 2022-09-02 10:23:25.788226+0800 rmc[93581:4984212] | JIGUANG | I - [JIGUANG] ----- login result ----- uid:64229360225 registrationID:171976fa8a7d321ee7a idc:1 2022-09-02 10:23:25.789450+0800 rmc[93581:4984222] | JIGUANG | D - [JIGUANG] +[JPUSHHelper postNotification:withUserInfo:] name: kJPUSHNetworkDidLoginNotification { time = 1662085405; version = 1; } 2022-09-02 10:23:25.789817+0800 rmc[93581:4984212] | JIGUANG | D - [JIGUANG] Action - doSendTcpRequest 2022-09-02 10:23:26.125730+0800 rmc[93581:4984212] | JIGUANG | D - [JIGUANG] send report:{ "app_key" = 02a9e9170e8c9d6871c5ceab; "app_version" = "1.0.1"; channel = dev; content = ( { date = "2022-09-02"; itime = 1662085405; "session_id" = c3c2a21ffc6c767896955cb3a5b72a41; time = "10:23:25"; timezone = "+8"; type = "active_launch"; } ); "core_sdk_ver" = "3.2.1"; platform = i; "sdk_ver" = "3.7.4"; "share_sdk_ver" = ""; "ssp_sdk_ver" = ""; "statistics_sdk_ver" = ""; uid = 64229360225; "verification_sdk_ver" = ""; } end, result:success 2022-09-02 10:23:26.126917+0800 rmc[93581:4984213] | JIGUANG | D - [JIGUANG] launchReport 成功 2022-09-02 10:23:26.258582+0800 rmc[93581:4984220] [javascript] 0 2022-09-02 10:23:26.258719+0800 rmc[93581:4984220] [javascript] null 2022-09-02 10:23:26.260768+0800 rmc[93581:4984220] [javascript] ┐ %c action %cconfig/clear %c@ 10:23:26.258 2022-09-02 10:23:26.263224+0800 rmc[93581:4984220] [javascript] │ '%c prev state', 'color: #9E9E9E; font-weight: bold', { config: { config: {} }, user: { user: null, token: '0', userId: '' }, baseUrl: { baseURL: '' } } 2022-09-02 10:23:26.263381+0800 rmc[93581:4984220] [javascript] │ '%c action ', 'color: #03A9F4; font-weight: bold', { type: 'config/clear' } 2022-09-02 10:23:26.263623+0800 rmc[93581:4984220] [javascript] │ '%c next state', 'color: #4CAF50; font-weight: bold', { config: { config: {} }, user: { user: null, token: '0', userId: '' }, baseUrl: { baseURL: '' } } 2022-09-02 10:23:26.263703+0800 rmc[93581:4984220] [javascript] ┘ 2022-09-02 10:23:26.286087+0800 rmc[93581:4984220] [javascript] 0 2022-09-02 10:23:26.286180+0800 rmc[93581:4984220] [javascript] null 2022-09-02 10:23:26.292765+0800 rmc[93581:4984220] [javascript] ┐ %c action %cconfig/clear %c@ 10:23:26.292 2022-09-02 10:23:26.293071+0800 rmc[93581:4984220] [javascript] │ '%c prev state', 'color: #9E9E9E; font-weight: bold', { config: { config: {} }, user: { user: null, token: '0', userId: '' }, baseUrl: { baseURL: '' } } 2022-09-02 10:23:26.293174+0800 rmc[93581:4984220] [javascript] │ '%c action ', 'color: #03A9F4; font-weight: bold', { type: 'config/clear' } 2022-09-02 10:23:26.293346+0800 rmc[93581:4984220] [javascript] │ '%c next state', 'color: #4CAF50; font-weight: bold', { config: { config: {} }, user: { user: null, token: '0', userId: '' }, baseUrl: { baseURL: '' } } 2022-09-02 10:23:26.293385+0800 rmc[93581:4984220] [javascript] ┘ 2022-09-02 10:23:26.456389+0800 rmc[93581:4984210] [connection] nw_socket_handle_socket_event [C12.1:1] Socket SO_ERROR [61: Connection refused] 2022-09-02 10:23:26.457936+0800 rmc[93581:4984210] [connection] nw_socket_handle_socket_event [C12.2:1] Socket SO_ERROR [61: Connection refused] 2022-09-02 10:23:26.458538+0800 rmc[93581:4984204] [connection] nw_connection_get_connected_socket [C12] Client called nw_connection_get_connected_socket on unconnected nw_connection 2022-09-02 10:23:26.458634+0800 rmc[93581:4984204] TCP Conn 0x28237d3f0 Failed : error 0:61 [61] 2022-09-02 10:23:27.473510+0800 rmc[93581:4984204] | JIGUANG | W - [JIGUANG] Not get deviceToken yet. After successful login, a custom message can be sent, but the APNs notification cannot. Until the deviceToken is obtained and reported successfully, the APNs notification can be used normally.

Paulinho89 commented 2 years ago

我这边也遇到了同样的问题,插件版本:2.9.3,楼主解决了吗

NapChen commented 2 years ago

我这边也遇到了同样的问题,插件版本:2.9.3,楼主解决了吗

只能先在AppDelegate.mm初始化了

Paulinho89 commented 2 years ago

我这边也遇到了同样的问题,插件版本:2.9.3,楼主解决了吗

只能先在AppDelegate.mm初始化了

确实是,我也是在AppDelegate.m中初始化的,但是还会遇到一个问题,就是我在Xcode中连着手机运行启动App,去极光平台发送测试消息可以正常收到消息。但是,一旦打包(打的是企业包)后安装到手机上,就收不到测试消息,看极光的后台报错显示说deviceToken获取失败,请问楼主有没有遇到我这种情况的问题?谢谢

选择的是开发环境测试 image

NapChen commented 2 years ago

我这边也遇到了同样的问题,插件版本:2.9.3,楼主解决了吗

只能先在AppDelegate.mm初始化了

确实是,我也是在AppDelegate.m中初始化的,但是还会遇到一个问题,就是我在Xcode中连着手机运行启动App,去极光平台发送测试消息可以正常收到消息。但是,一旦打包(打的是企业包)后安装到手机上,就收不到测试消息,看极光的后台报错显示说deviceToken获取失败,请问楼主有没有遇到我这种情况的问题?谢谢

选择的是开发环境测试 image

我打的Ad包是能够正常收到推送的,如果是正式的打包后台发推送应该选生产环境吧。另外就是检查你的推送证书了

dev-ylyl commented 2 years ago

[APNS上报 也放到js里]

按照这个commit,打一个patch就可以解决了。

NapChen commented 2 years ago

[APNS上报 也放到js里]

按照这个commit,打一个patch就可以解决了。

可以提交个PR吗?

yqz0203 commented 1 year ago

请问下还需要哪里配置吗?我弹不出请求通知权限的弹框。