From c415358f41bbc9eaa9ede11e2325775f703f45d7 Mon Sep 17 00:00:00 2001
From: PRLsir <18824673092@163.com>
Date: Thu, 25 Nov 2021 17:11:49 +0800
Subject: [PATCH] =?UTF-8?q?[APNS=E4=B8=8A=E6=8A=A5=20=E4=B9=9F=E6=94=BE?=
=?UTF-8?q?=E5=88=B0js=E9=87=8C]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/App.js | 2 +-
example/ios/Podfile.lock | 8 +++---
example/ios/example/AppDelegate.m | 26 +++++++++---------
example/ios/example/Info.plist | 4 +++
ios/RCTJPushModule/RCTJPushModule.m | 42 ++++++++++++++++++++---------
5 files changed, 51 insertions(+), 31 deletions(-)
diff --git a/example/App.js b/example/App.js
index 55187fb4..eb8c252c 100644
--- a/example/App.js
+++ b/example/App.js
@@ -52,7 +52,7 @@ export default class App extends React.Component {
}
componentDidMount() {
- JPush.init({"appKey":"129c21dc4cb5e6f6de194003","channel":"dev","production":1});
+ JPush.init({"appKey":"02c7f79c9248ecadf25140f7","channel":"dev","production":1});
//连接状态
this.connectListener = result => {
console.log("connectListener:" + JSON.stringify(result))
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
index 6b1aeff7..b715ecbc 100644
--- a/example/ios/Podfile.lock
+++ b/example/ios/Podfile.lock
@@ -11,9 +11,9 @@ PODS:
- DoubleConversion
- glog
- glog (0.3.5)
- - JCore (1.9.2):
+ - JCore (1.9.5):
- React
- - JPush (2.8.3):
+ - JPush (2.8.8):
- React
- React (0.60.5):
- React-Core (= 0.60.5)
@@ -167,8 +167,8 @@ SPEC CHECKSUMS:
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
- JCore: 82ea6d26c4c30dde4ec9553b0c8fe87eebfa5142
- JPush: 5941cabd5ffdd5d3186759f089acd2fcdd59905e
+ JCore: 7e9473558d4e2e80fc2204610035051eefd093fd
+ JPush: 04e6b729162edf8ab9d7f4e3f578d3fbdd591d26
React: 53c53c4d99097af47cf60594b8706b4e3321e722
React-Core: ba421f6b4f4cbe2fb17c0b6fc675f87622e78a64
React-cxxreact: 8384287780c4999351ad9b6e7a149d9ed10a2395
diff --git a/example/ios/example/AppDelegate.m b/example/ios/example/AppDelegate.m
index 3dddfe2e..e3f644c6 100644
--- a/example/ios/example/AppDelegate.m
+++ b/example/ios/example/AppDelegate.m
@@ -21,20 +21,20 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// JPush初始化配置 可以延时初始化 不再强制在此初始化,在js里可以直接调用init
-// [JPUSHService setupWithOption:launchOptions appKey:@"129c21dc4cb5e6f6de194003"
+// [JPUSHService setupWithOption:launchOptions appKey:@"02c7f79c9248ecadf25140f7"
// channel:@"dev" apsForProduction:YES];
- // APNS
- 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];
- // 地理围栏
- [JPUSHService registerLbsGeofenceDelegate:self withLaunchOptions:launchOptions];
+// // APNS
+// 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];
+// // 地理围栏
+// [JPUSHService registerLbsGeofenceDelegate:self withLaunchOptions:launchOptions];
// ReactNative环境配置
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
diff --git a/example/ios/example/Info.plist b/example/ios/example/Info.plist
index 20fb35c9..22032f6f 100644
--- a/example/ios/example/Info.plist
+++ b/example/ios/example/Info.plist
@@ -39,6 +39,10 @@
NSLocationWhenInUseUsageDescription
+ UIBackgroundModes
+
+ remote-notification
+
UILaunchStoryboardName
LaunchScreen
UIRequiredDeviceCapabilities
diff --git a/ios/RCTJPushModule/RCTJPushModule.m b/ios/RCTJPushModule/RCTJPushModule.m
index a7ebc87e..3ec9e4f1 100644
--- a/ios/RCTJPushModule/RCTJPushModule.m
+++ b/ios/RCTJPushModule/RCTJPushModule.m
@@ -122,19 +122,35 @@ - (id)init
RCT_EXPORT_METHOD(setupWithConfig:(NSDictionary *)params)
{
if (params[@"appKey"] && params[@"channel"] && params[@"production"]) {
- // JPush初始化配置
- NSMutableDictionary *launchOptions = [NSMutableDictionary dictionaryWithDictionary:self.bridge.launchOptions];
- [JPUSHService setupWithOption:launchOptions appKey:params[@"appKey"]
- channel:params[@"channel"] apsForProduction:[params[@"production"] boolValue]];
- }
- NSMutableArray *notificationList = [RCTJPushEventQueue sharedInstance]._notificationQueue;
- if(notificationList.count) {
- [self sendApnsNotificationEventByDictionary:notificationList[0]];
- }
- NSMutableArray *localNotificationList = [RCTJPushEventQueue sharedInstance]._localNotificationQueue;
- if(localNotificationList.count) {
- [self sendLocalNotificationEventByDictionary:localNotificationList[0]];
- }
+ // JPush初始化配置
+ NSMutableDictionary *launchOptions = [NSMutableDictionary dictionaryWithDictionary:self.bridge.launchOptions];
+ [JPUSHService setupWithOption:launchOptions appKey:params[@"appKey"]
+ channel:params[@"channel"] apsForProduction:[params[@"production"] boolValue]];
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ // APNS
+ JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
+ if (@available(iOS 12.0, *)) {
+ entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
+ }
+ [JPUSHService registerForRemoteNotificationConfig:entity delegate:self.bridge.delegate];
+ [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
+ // 自定义消息
+ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
+ [defaultCenter addObserver:self.bridge.delegate selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];
+ // 地理围栏
+ [JPUSHService registerLbsGeofenceDelegate:self.bridge.delegate withLaunchOptions:launchOptions];
+ });
+
+ NSMutableArray *notificationList = [RCTJPushEventQueue sharedInstance]._notificationQueue;
+ if(notificationList.count) {
+ [self sendApnsNotificationEventByDictionary:notificationList[0]];
+ }
+ NSMutableArray *localNotificationList = [RCTJPushEventQueue sharedInstance]._localNotificationQueue;
+ if(localNotificationList.count) {
+ [self sendLocalNotificationEventByDictionary:localNotificationList[0]];
+ }
+ }
}
RCT_EXPORT_METHOD(loadJS)