Skip to content

Commit faccc49

Browse files
committed
优化【JIRA单:VIP新宏基Jpush-RN无法控制iOS初始化】问题
1 parent 3836c38 commit faccc49

File tree

8 files changed

+80
-30
lines changed

8 files changed

+80
-30
lines changed

example/App.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class App extends React.Component {
5252
}
5353

5454
componentDidMount() {
55-
JPush.init();
55+
JPush.init({"appKey":"129c21dc4cb5e6f6de194003","channel":"dev","production":1});
5656
//连接状态
5757
this.connectListener = result => {
5858
console.log("connectListener:" + JSON.stringify(result))
@@ -69,10 +69,10 @@ export default class App extends React.Component {
6969
};
7070
JPush.addLocalNotificationListener(this.localNotificationListener);
7171
//自定义消息回调
72-
this.customMessageListener = result => {
73-
console.log("customMessageListener:" + JSON.stringify(result))
74-
};
75-
JPush.addCustomMessagegListener(this.customMessageListener);
72+
// this.customMessageListener = result => {
73+
// console.log("customMessageListener:" + JSON.stringify(result))
74+
// };
75+
// JPush.addCustomMessagegListener(this.customMessageListener);
7676
//tag alias事件回调
7777
this.tagAliasListener = result => {
7878
console.log("tagAliasListener:" + JSON.stringify(result))

example/ios/Podfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,31 @@ target 'example' do
2929

3030
use_native_modules!
3131
end
32+
33+
post_install do |installer|
34+
## Fix for XCode 12.5
35+
find_and_replace(
36+
"../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
37+
"_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules",
38+
"_initializeModules:(NSArray<Class> *)modules")
39+
40+
find_and_replace(
41+
"../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
42+
"RCTBridgeModuleNameForClass(module))",
43+
"RCTBridgeModuleNameForClass(Class(module)))"
44+
)
45+
end
46+
47+
def find_and_replace(dir, findstr, replacestr)
48+
Dir[dir].each do |name|
49+
text = File.read(name)
50+
replace = text.gsub(findstr,replacestr)
51+
if text != replace
52+
puts "Fix: " + name
53+
File.open(name, "w") { |file| file.puts replace }
54+
STDOUT.flush
55+
end
56+
end
57+
Dir[dir + '*/'].each(&method(:find_and_replace))
58+
end
59+

example/ios/Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ PODS:
1111
- DoubleConversion
1212
- glog
1313
- glog (0.3.5)
14-
- JCore (1.6.0):
14+
- JCore (1.9.2):
1515
- React
16-
- JPush (2.7.0):
16+
- JPush (2.8.3):
1717
- React
1818
- React (0.60.5):
1919
- React-Core (= 0.60.5)
@@ -167,8 +167,8 @@ SPEC CHECKSUMS:
167167
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
168168
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
169169
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
170-
JCore: 54f06adbbb4a28c11e8bd2466d2a0656ec2f16c9
171-
JPush: 8fc065186252835feb4959274fc7bd140dfce2c4
170+
JCore: 82ea6d26c4c30dde4ec9553b0c8fe87eebfa5142
171+
JPush: 5941cabd5ffdd5d3186759f089acd2fcdd59905e
172172
React: 53c53c4d99097af47cf60594b8706b4e3321e722
173173
React-Core: ba421f6b4f4cbe2fb17c0b6fc675f87622e78a64
174174
React-cxxreact: 8384287780c4999351ad9b6e7a149d9ed10a2395
@@ -188,6 +188,6 @@ SPEC CHECKSUMS:
188188
React-RCTWebSocket: cd932a16b7214898b6b7f788c8bddb3637246ac4
189189
yoga: 312528f5bbbba37b4dcea5ef00e8b4033fdd9411
190190

191-
PODFILE CHECKSUM: 2d51da6f6de1005d1437b85332a1464eeda5bfbc
191+
PODFILE CHECKSUM: 8e66ba6295c7bad5d297ef1390be0790edfec7aa
192192

193-
COCOAPODS: 1.8.4
193+
COCOAPODS: 1.11.2

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
TargetAttributes = {
202202
13B07F861A680F5B00A75B9A = {
203203
DevelopmentTeam = 8X2A38Q9VD;
204-
ProvisioningStyle = Manual;
204+
ProvisioningStyle = Automatic;
205205
SystemCapabilities = {
206206
com.apple.Push = {
207207
enabled = 1;
@@ -357,11 +357,11 @@
357357
buildSettings = {
358358
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
359359
CODE_SIGN_ENTITLEMENTS = example/example.entitlements;
360-
CODE_SIGN_IDENTITY = "iPhone Developer: 旭东 饶 (N62595JLRL)";
361-
CODE_SIGN_STYLE = Manual;
360+
CODE_SIGN_IDENTITY = "Apple Development";
361+
CODE_SIGN_STYLE = Automatic;
362362
CURRENT_PROJECT_VERSION = 1;
363363
DEAD_CODE_STRIPPING = NO;
364-
DEVELOPMENT_TEAM = 8X2A38Q9VD;
364+
DEVELOPMENT_TEAM = "";
365365
HEADER_SEARCH_PATHS = (
366366
"$(inherited)",
367367
"\"${PODS_ROOT}/Headers/Public\"",
@@ -394,9 +394,9 @@
394394
"-ObjC",
395395
"-lc++",
396396
);
397-
PRODUCT_BUNDLE_IDENTIFIER = io.jiguang.hxhg;
397+
PRODUCT_BUNDLE_IDENTIFIER = com.jiguang.verification;
398398
PRODUCT_NAME = example;
399-
PROVISIONING_PROFILE_SPECIFIER = JIGUANGSDK;
399+
PROVISIONING_PROFILE_SPECIFIER = "";
400400
VERSIONING_SYSTEM = "apple-generic";
401401
};
402402
name = Debug;
@@ -407,10 +407,10 @@
407407
buildSettings = {
408408
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
409409
CODE_SIGN_ENTITLEMENTS = example/example.entitlements;
410-
CODE_SIGN_IDENTITY = "iPhone Developer: 旭东 饶 (N62595JLRL)";
411-
CODE_SIGN_STYLE = Manual;
410+
CODE_SIGN_IDENTITY = "Apple Development";
411+
CODE_SIGN_STYLE = Automatic;
412412
CURRENT_PROJECT_VERSION = 1;
413-
DEVELOPMENT_TEAM = 8X2A38Q9VD;
413+
DEVELOPMENT_TEAM = "";
414414
HEADER_SEARCH_PATHS = (
415415
"$(inherited)",
416416
"\"${PODS_ROOT}/Headers/Public\"",
@@ -443,9 +443,9 @@
443443
"-ObjC",
444444
"-lc++",
445445
);
446-
PRODUCT_BUNDLE_IDENTIFIER = io.jiguang.hxhg;
446+
PRODUCT_BUNDLE_IDENTIFIER = com.jiguang.verification;
447447
PRODUCT_NAME = example;
448-
PROVISIONING_PROFILE_SPECIFIER = JIGUANGSDK;
448+
PROVISIONING_PROFILE_SPECIFIER = "";
449449
VERSIONING_SYSTEM = "apple-generic";
450450
};
451451
name = Release;

example/ios/example/AppDelegate.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
@implementation AppDelegate
2121

2222
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
23-
// JPush初始化配置
24-
[JPUSHService setupWithOption:launchOptions appKey:@"129c21dc4cb5e6f6de194003"
25-
channel:@"dev" apsForProduction:YES];
23+
// JPush初始化配置 可以延时初始化 不再强制在此初始化,在js里可以直接调用init
24+
// [JPUSHService setupWithOption:launchOptions appKey:@"129c21dc4cb5e6f6de194003"
25+
// channel:@"dev" apsForProduction:YES];
2626
// APNS
2727
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
2828
if (@available(iOS 12.0, *)) {

index.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ export default class JPush {
5656

5757
/**
5858
* 初始化推送服务
59-
*
59+
* {"appKey":"","channel":"dev","production":1}
6060
* 请在componentDidMount()调用init,否则会影响通知点击事件的回调
6161
*
6262
*/
63-
static init(): void;
63+
static init(params: {
64+
appKey: string;
65+
titchannelle: string;
66+
production: boolean;
67+
}): void;
6468

6569
/**
6670
* 获取 RegistrationID

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export default class JPush {
2828

2929
/*
3030
* 初始化推送服务
31-
*
31+
* {"appKey":"","channel":"dev","production":1}
3232
* 请在componentDidMount()调用init,否则会影响通知点击事件的回调
3333
* */
34-
static init() {
34+
static init(params) {
3535
if (Platform.OS == "android") {
3636
JPushModule.init()
3737
} else {
38-
JPushModule.loadJS()
38+
JPushModule.setupWithConfig(params)
3939
}
4040
}
4141

ios/RCTJPushModule/RCTJPushModule.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ - (id)init
119119
}
120120
}
121121

122+
RCT_EXPORT_METHOD(setupWithConfig:(NSDictionary *)params)
123+
{
124+
if (params[@"appKey"] && params[@"channel"] && params[@"production"]) {
125+
// JPush初始化配置
126+
NSMutableDictionary *launchOptions = [NSMutableDictionary dictionaryWithDictionary:self.bridge.launchOptions];
127+
[JPUSHService setupWithOption:launchOptions appKey:params[@"appKey"]
128+
channel:params[@"channel"] apsForProduction:[params[@"production"] boolValue]];
129+
}
130+
NSMutableArray *notificationList = [RCTJPushEventQueue sharedInstance]._notificationQueue;
131+
if(notificationList.count) {
132+
[self sendApnsNotificationEventByDictionary:notificationList[0]];
133+
}
134+
NSMutableArray *localNotificationList = [RCTJPushEventQueue sharedInstance]._localNotificationQueue;
135+
if(localNotificationList.count) {
136+
[self sendLocalNotificationEventByDictionary:localNotificationList[0]];
137+
}
138+
}
139+
122140
RCT_EXPORT_METHOD(loadJS)
123141
{
124142
NSMutableArray *notificationList = [RCTJPushEventQueue sharedInstance]._notificationQueue;

0 commit comments

Comments
 (0)