Skip to content

Commit

Permalink
Merge pull request #301 from jpush/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KenChoi1992 authored Aug 4, 2017
2 parents 15afcc8 + 351904d commit 11c7103
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void onCatalystInstanceDestroy() {
mCachedBundle = null;
if (null != sCacheMap) {
sCacheMap.clear();
sCacheMap = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.jpush.reactnativejpush;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
Expand All @@ -24,11 +23,6 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
});
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
Expand Down
8 changes: 3 additions & 5 deletions example/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ node_modules/react-native/flow
flow/

[options]
emoji=true

module.system=haste

experimental.strict_type_args=true
Expand All @@ -36,11 +34,11 @@ suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-8]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-8]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-7]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-7]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy

unsafe.enable_getters_and_setters=true

[version]
^0.38.0
^0.37.0
22 changes: 21 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,33 @@ DerivedData
*.xcuserstate
project.xcworkspace

# Android/IJ
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
android/app/libs
*.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ dependencies {
compile project(':jpush-react-native')
compile project(':jcore-react-native')
compile "com.android.support:appcompat-v7:25.3.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.facebook.react:react-native:0.47.1" // From node_modules
}

// Run this once to be able to run the application with BUCK
Expand Down
4 changes: 4 additions & 0 deletions example/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "PushDemo",
"displayName": "PushDemo"
}
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {
"jcore-react-native": "^1.1.5",
"jpush-react-native": "^1.7.1",
"react": "^15.4.0",
"react-native": "^0.41.2",
"react": "^16.0.0-alpha.12",
"react-native": "^0.47.1",
"react-native-onesignal": "^3.0.4",
"react-navigation": "^1.0.0-beta.11"
},
Expand Down
24 changes: 7 additions & 17 deletions example/react-native-iOS/push_activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,12 @@ var PushActivity = React.createClass({
this.props.navigator.push({ name:'LocalPushActivity' });
},
componentWillMount() {

// NativeAppEventEmitter.addListener('networkDidSetup', (token) => {
// this.setState({ connectStatus: '已连接' });
// });
// NativeAppEventEmitter.addListener('networkDidClose', (token) => {
// this.setState({ connectStatus: '连接已断开' });
// });
// NativeAppEventEmitter.addListener('networkDidRegister', (token) => {
// this.setState({ connectStatus: '已注册' });
// });
// NativeAppEventEmitter.addListener('networkDidLogin', (token) => {
// this.setState({ connectStatus: '已登陆' });
// });
JPushModule.addnetworkDidLoginListener(() => {
Alert.alert('连接已登录')

JPushModule.addTags(['dasffas'], (result)=> {
Alert.alert('addTags success:' + JSON.stringify(result))
})
})

JPushModule.addConnectionChangeListener((result) => {
Expand All @@ -71,11 +62,10 @@ var PushActivity = React.createClass({
Alert.alert('网络已断开')
}
})
var subscription = NativeAppEventEmitter.addListener(
'ReceiveNotification',
(notification) => console.log(notification)
);

JPushModule.addReceiveNotificationListener((notification) => {
Alert.alert(JSON.stringify(notification))
})
},
componentDidMount() {

Expand Down
38 changes: 36 additions & 2 deletions ios/RCTJPushModule/RCTJPushModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,20 @@ + (id)allocWithZone:(NSZone *)zone {

- (id)init {
self = [super init];

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter removeObserver:self];


[defaultCenter addObserver:self
selector:@selector(networkConnecting:)
name:kJPFNetworkIsConnectingNotification
object:nil];

[defaultCenter addObserver:self
selector:@selector(networkRegister:)
name:kJPFNetworkDidRegisterNotification
object:nil];

[defaultCenter addObserver:self
selector:@selector(networkDidSetup:)
Expand Down Expand Up @@ -110,6 +120,12 @@ - (void)reactJSDidload {
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFOpenNotificationToLaunchApp object:[RCTJPushActionQueue sharedInstance].openedLocalNotification];
}

if (_isJPushDidLogin) {
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFNetworkDidLoginNotification object:nil];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:kJPFNetworkDidCloseNotification object:nil];
}

}

- (void)setBridge:(RCTBridge *)bridge {
Expand Down Expand Up @@ -144,22 +160,40 @@ - (void)openNotification:(NSNotification *)notification {
[self.bridge.eventDispatcher sendAppEventWithName:@"openNotification" body:obj];
}


- (void)networkConnecting:(NSNotification *)notification {
_isJPushDidLogin = false;
[self.bridge.eventDispatcher sendAppEventWithName:@"connectionChange"
body:@(false)];
}

- (void)networkRegister:(NSNotification *)notification {
_isJPushDidLogin = false;
[self.bridge.eventDispatcher sendAppEventWithName:@"connectionChange"
body:@(false)];
}

- (void)networkDidSetup:(NSNotification *)notification {
_isJPushDidLogin = false;
[self.bridge.eventDispatcher sendAppEventWithName:@"connectionChange"
body:@(true)];
}

- (void)networkDidClose:(NSNotification *)notification {
_isJPushDidLogin = false;
[self.bridge.eventDispatcher sendAppEventWithName:@"connectionChange"
body:@(true)];
body:@(false)];
}


- (void)networkDidLogin:(NSNotification *)notification {
_isJPushDidLogin = YES;
[[RCTJPushActionQueue sharedInstance] scheduleGetRidCallbacks];
// [self.bridge.eventDispatcher sendAppEventWithName:@"connectionChange"
// body:@(true)];
[self.bridge.eventDispatcher sendAppEventWithName:@"networkDidLogin"
body:nil];

}

- (void)networkDidReceiveMessage:(NSNotification *)notification {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jpush-react-native",
"version": "2.0.0",
"version": "2.0.1",
"description": "a jpush plugin for react native application",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 11c7103

Please sign in to comment.