Skip to content

Commit

Permalink
[APNS上报 也放到js里]
Browse files Browse the repository at this point in the history
  • Loading branch information
PRLsir authored and liupr committed Jul 29, 2022
1 parent d810ef2 commit 029b2bb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
2 changes: 1 addition & 1 deletion example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions example/ios/example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions example/ios/example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
42 changes: 29 additions & 13 deletions ios/RCTJPushModule/RCTJPushModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"types": "index.d.ts",
"license": "ISC",
"author": "wicked.tc130",
<<<<<<< HEAD
"version": "2.9.2",
=======
"version": "2.8.9",
>>>>>>> fa7b3b0 ([APNS上报 也放到js里])
"repository": {
"type": "git",
"url": "https://github.com/jpush/jpush-react-native"
Expand Down

0 comments on commit 029b2bb

Please sign in to comment.