Skip to content

Commit 43d571a

Browse files
KenChoiKenChoi
authored andcommitted
combine getRegistrationId and addGetRegistrationIdListener
1 parent 2c41854 commit 43d571a

File tree

8 files changed

+101
-107
lines changed

8 files changed

+101
-107
lines changed

android/build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
buildscript {
2-
repositories {
3-
jcenter()
4-
}
5-
6-
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.3.1'
8-
}
9-
}
10-
111
apply plugin: 'com.android.library'
122

133
android {

android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Date;
2929
import java.util.HashMap;
3030
import java.util.HashSet;
31-
import java.util.Iterator;
3231
import java.util.LinkedHashSet;
3332
import java.util.List;
3433
import java.util.Set;
@@ -55,6 +54,7 @@ public class JPushModule extends ReactContextBaseJavaModule {
5554
private final static String CONNECTION_CHANGE = "connectionChange";
5655

5756
private static HashMap<Integer, Callback> sCacheMap = new HashMap<Integer, Callback>();
57+
private static Callback mGetRidCallback;
5858

5959
public JPushModule(ReactApplicationContext reactContext) {
6060
super(reactContext);
@@ -81,7 +81,10 @@ public void onCatalystInstanceDestroy() {
8181
mCachedBundle = null;
8282
if (null != sCacheMap) {
8383
sCacheMap.clear();
84+
sCacheMap = null;
8485
}
86+
mEvent = null;
87+
mGetRidCallback = null;
8588
}
8689

8790
@ReactMethod
@@ -157,6 +160,10 @@ private static void sendEvent() {
157160
.emit(mEvent, map);
158161
break;
159162
case RECEIVE_REGISTRATION_ID:
163+
if (mGetRidCallback != null) {
164+
mGetRidCallback.invoke(mCachedBundle.getString(JPushInterface.EXTRA_REGISTRATION_ID));
165+
mGetRidCallback = null;
166+
}
160167
mRAC.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
161168
.emit(mEvent, mCachedBundle.getString(JPushInterface.EXTRA_REGISTRATION_ID));
162169
break;
@@ -375,7 +382,11 @@ public void getRegistrationID(Callback callback) {
375382
try {
376383
mContext = getCurrentActivity();
377384
String id = JPushInterface.getRegistrationID(mContext);
378-
callback.invoke(id);
385+
if (id != null) {
386+
callback.invoke(id);
387+
} else {
388+
mGetRidCallback = callback;
389+
}
379390
} catch (Exception e) {
380391
e.printStackTrace();
381392
}
@@ -656,6 +667,7 @@ public void jumpToPushActivity(String activityName) {
656667
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
657668
intent.setClassName(mRAC, mRAC.getPackageName() + "." + activityName);
658669
mRAC.startActivity(intent);
670+
659671
} catch (Exception e) {
660672
e.printStackTrace();
661673
}

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def enableSeparateBuildPerCPUArchitecture = false
7878
def enableProguardInReleaseBuilds = false
7979
android {
8080
compileSdkVersion 25
81-
buildToolsVersion "25.0.2"
81+
buildToolsVersion "26.0.2"
8282

8383
defaultConfig {
8484
applicationId "com.pushdemo"

example/android/build.gradle

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
buildscript {
44
repositories {
55
jcenter()
6-
maven {
7-
url 'https://oss.sonatype.org/content/repositories/snapshots/'
8-
}
9-
maven {
10-
url 'https://maven.google.com'
11-
}
12-
maven {
13-
url 'https://dl.google.com/dl/android/maven2/'
14-
}
6+
google()
157
}
168
dependencies {
17-
classpath 'com.android.tools.build:gradle:3.0.0-beta4'
9+
classpath 'com.android.tools.build:gradle:3.0.1'
1810

1911
// NOTE: Do not place your application dependencies here; they belong
2012
// in the individual module build.gradle files

example/documents/APIs.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ reset tags.
102102
- sendLocalNotification(notification)
103103

104104
- **buildId** : Number // set local notification styles,1 defoult style,2 custom style( you should call setStyleCustom frist) (Android Only)
105-
- **id** : Number // local notification identify,l you can use it to cancel local notification
106-
- **title** : String // local notification title
107-
- **content** : String // local notification content
105+
- **id** : Number // local notification identify,l you can use it to cancel local notification
106+
- **title** : String // local notification title
107+
- **content** : String // local notification content
108108
- **extra** : Object // local notification extra (key-value)
109109
- **fireTime** : Number // show local notification time(ms)
110110
- **badge** : Number // when local notification fire, application icon will set badge with this value (iOS Only)
@@ -405,15 +405,15 @@ setLocalNotification( Date, // date local notification fire data
405405

406406
407407

408-
- #### addGetRegistrationIdListener
408+
- #### addGetRegistrationIdListener(^2.1.4 Deprecated, use [getRegistrationId](#getregistrationid) instead)
409409

410410
If add this listener, when finished registering device, open app will invoke this callback.
411411

412412
```
413413
JPushModule.addGetRegistrationIdListener(cb)
414414
```
415415

416-
- #### removeGetRegistrationIdListener
416+
- #### removeGetRegistrationIdListener(^2.1.4 Deprecated)
417417

418418
Remove listener. `removeGetRegistrationIdListener` and `addGetRegistrationIdListener` should used in pairs.
419419

example/documents/APIs_zh.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ Android 和 iOS 通用 API。
133133
- sendLocalNotification(notification)
134134

135135
- **buildId** : Number // 设置通知样式,1 为基础样式,2 为自定义样式。自定义样式需要先调用 setStyleCustom 接口设置自定义样式。(Android Only)
136-
- **id** : Number // 通知的 id, 可用于取消通知
137-
- **title** : String // 通知标题
138-
- **content** : String // 通知内容
136+
- **id** : Number // 通知的 id, 可用于取消通知
137+
- **title** : String // 通知标题
138+
- **content** : String // 通知内容
139139
- **extra** : Object // extra 字段
140140
- **fireTime** : Number // 通知触发时间的时间戳(毫秒)
141141
- **badge** : Number // 本地推送触发后应用角标的 badge 值 (iOS Only)
@@ -434,15 +434,15 @@ setLocalNotification( Date, // date 触发本地推送的时间
434434

435435
436436

437-
- #### addGetRegistrationIdListener
437+
- #### addGetRegistrationIdListener (^2.1.4 Deprecated, 使用 [getRegistrationId](#getregistrationid) 代替)
438438

439439
如果添加这个监听,设备注册成功后,打开应用将会回调这个事件。
440440

441441
```
442442
JPushModule.addGetRegistrationIdListener(cb)
443443
```
444444

445-
- #### removeGetRegistrationIdListener
445+
- #### removeGetRegistrationIdListener (^2.1.4 Deprecated)
446446

447447
移除监听 registrationId 事件,与 `addGetRegistrationIdListener` 成对使用。
448448

example/react-native-android/push_activity.js

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default class PushActivity extends React.Component {
7979
});
8080
}
8181

82-
componentWillMount() {}
82+
componentWillMount() { }
8383

8484
componentDidMount() {
8585
JPushModule.getInfo((map) => {
@@ -92,7 +92,7 @@ export default class PushActivity extends React.Component {
9292
});
9393
});
9494
JPushModule.notifyJSDidLoad((resultCode) => {
95-
if (resultCode === 0) {}
95+
if (resultCode === 0) { }
9696
});
9797
JPushModule.addReceiveCustomMsgListener((map) => {
9898
this.setState({
@@ -140,84 +140,84 @@ export default class PushActivity extends React.Component {
140140

141141
render() {
142142
return (
143-
<ScrollView style={ styles.parent }>
143+
<ScrollView style={styles.parent}>
144144

145-
<Text style={ styles.textStyle }>
146-
{ this.state.appkey }
147-
</Text>
148-
<Text style={ styles.textStyle }>
149-
{ this.state.imei }
150-
</Text>
151-
<Text style={ styles.textStyle }>
152-
{ this.state.package }
153-
</Text>
154-
<Text style={ styles.textStyle }>
155-
{ this.state.deviceId }
156-
</Text>
157-
<Text style={ styles.textStyle }>
158-
{ this.state.version }
159-
</Text>
160-
<TouchableHighlight
161-
underlayColor='#0866d9'
162-
activeOpacity={ 0.5 }
163-
style={ styles.btnStyle }
164-
onPress={ this.jumpSetActivity }>
165-
<Text style={ styles.btnTextStyle }>
166-
设置
145+
<Text style={styles.textStyle}>
146+
{this.state.appkey}
147+
</Text>
148+
<Text style={styles.textStyle}>
149+
{this.state.imei}
150+
</Text>
151+
<Text style={styles.textStyle}>
152+
{this.state.package}
153+
</Text>
154+
<Text style={styles.textStyle}>
155+
{this.state.deviceId}
156+
</Text>
157+
<Text style={styles.textStyle}>
158+
{this.state.version}
159+
</Text>
160+
<TouchableHighlight
161+
underlayColor='#0866d9'
162+
activeOpacity={0.5}
163+
style={styles.btnStyle}
164+
onPress={this.jumpSetActivity}>
165+
<Text style={styles.btnTextStyle}>
166+
设置
167167
</Text>
168-
</TouchableHighlight>
169-
<TouchableHighlight
170-
underlayColor='#0866d9'
171-
activeOpacity={ 0.5 }
172-
style={ styles.btnStyle }
173-
onPress={ this.onInitPress }>
174-
<Text style={ styles.btnTextStyle }>
175-
INITPUSH
168+
</TouchableHighlight>
169+
<TouchableHighlight
170+
underlayColor='#0866d9'
171+
activeOpacity={0.5}
172+
style={styles.btnStyle}
173+
onPress={this.onInitPress}>
174+
<Text style={styles.btnTextStyle}>
175+
INITPUSH
176176
</Text>
177-
</TouchableHighlight>
178-
<TouchableHighlight
179-
underlayColor='#e4083f'
180-
activeOpacity={ 0.5 }
181-
style={ styles.btnStyle }
182-
onPress={ this.onStopPress }>
183-
<Text style={ styles.btnTextStyle }>
184-
STOPPUSH
177+
</TouchableHighlight>
178+
<TouchableHighlight
179+
underlayColor='#e4083f'
180+
activeOpacity={0.5}
181+
style={styles.btnStyle}
182+
onPress={this.onStopPress}>
183+
<Text style={styles.btnTextStyle}>
184+
STOPPUSH
185185
</Text>
186-
</TouchableHighlight>
187-
<TouchableHighlight
188-
underlayColor='#f5a402'
189-
activeOpacity={ 0.5 }
190-
style={ styles.btnStyle }
191-
onPress={ this.onResumePress }>
192-
<Text style={ styles.btnTextStyle }>
193-
RESUMEPUSH
186+
</TouchableHighlight>
187+
<TouchableHighlight
188+
underlayColor='#f5a402'
189+
activeOpacity={0.5}
190+
style={styles.btnStyle}
191+
onPress={this.onResumePress}>
192+
<Text style={styles.btnTextStyle}>
193+
RESUMEPUSH
194194
</Text>
195-
</TouchableHighlight>
196-
<TouchableHighlight
197-
underlayColor='#f5a402'
198-
activeOpacity={ 0.5 }
199-
style={ styles.btnStyle }
200-
onPress={ this.onGetRegistrationIdPress }>
201-
<Text style={ styles.btnTextStyle }>
202-
GET REGISTRATIONID
195+
</TouchableHighlight>
196+
<TouchableHighlight
197+
underlayColor='#f5a402'
198+
activeOpacity={0.5}
199+
style={styles.btnStyle}
200+
onPress={this.onGetRegistrationIdPress}>
201+
<Text style={styles.btnTextStyle}>
202+
GET REGISTRATIONID
203203
</Text>
204-
</TouchableHighlight>
205-
<TouchableHighlight
206-
underlayColor='#f5a402'
207-
activeOpacity={ 0.5 }
208-
style={ styles.btnStyle }
209-
onPress={ this.jumpSecondActivity }>
210-
<Text style={ styles.btnTextStyle }>
211-
Go to SecondActivity
204+
</TouchableHighlight>
205+
<TouchableHighlight
206+
underlayColor='#f5a402'
207+
activeOpacity={0.5}
208+
style={styles.btnStyle}
209+
onPress={this.jumpSecondActivity}>
210+
<Text style={styles.btnTextStyle}>
211+
Go to SecondActivity
212212
</Text>
213-
</TouchableHighlight>
214-
<Text style={ styles.textStyle }>
215-
{ this.state.pushMsg }
216-
</Text>
217-
<Text style={styles.textStyle}>
218-
{ this.state.registrationId }
219-
</Text>
220-
</ScrollView>
213+
</TouchableHighlight>
214+
<Text style={styles.textStyle}>
215+
{this.state.pushMsg}
216+
</Text>
217+
<Text style={styles.textStyle}>
218+
{this.state.registrationId}
219+
</Text>
220+
</ScrollView>
221221

222222
)
223223
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jpush-react-native",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "a jpush plugin for react native application",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)