Skip to content

Commit 2998877

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents eedc84b + 6d9e601 commit 2998877

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,38 @@
1515
```
1616
npm install jpush-react-native jcore-react-native --save
1717
```
18+
## 配置
1819

19-
##### (如果是原生应用集成 react-native)使用 CocoaPods 安装
20+
配置包括两个步骤,自动配置和手动操作。
2021

21-
在 Podfile 中添加如下代码:
22+
### 1.自动配置部分(以下命令均在你的 React Native Project 目录下运行)
2223

24+
如果工程不是通过 Cocoapods 来集成 ReactNative 的可以直接使用下面代码来 link 插件。
2325
```
24-
pod 'JPushRN', :path => '../node_modules/jpush-react-native'
26+
react-native link
2527
```
2628

27-
终端执行如下指令:
29+
根据提示,输入 `appKey` 等即可。
2830

29-
```
30-
pod install
31-
```
31+
自动配置操作会自动插入 Native 代码(iOS 中使用 Appdelegate.m 文件名,如果修改了该文件名需要手动插入[代码](documents/ios_usage.md)),这个部分用户无需关系具体细节。
3232

33-
## 配置
3433

35-
配置包括两个步骤,自动配置和手动操作。
3634

37-
### 1.自动配置部分(以下命令均在你的 React Native Project 目录下运行)
35+
##### (如果是原生应用集成 react-native)使用 CocoaPods 安装
36+
37+
##### 如果你的 React Native 是通过 Cocoapods 来集成的则使用下面两个步骤来集成,注意: 使用 pod 就不要使用 react-native link 了,不然会有冲突。
38+
39+
1. 在 Podfile 中添加如下代码:
3840

3941
```
40-
react-native link
42+
pod 'JPushRN', :path => '../node_modules/jpush-react-native'
4143
```
4244

43-
根据提示,输入 `appKey` 等即可。
45+
2. 终端执行如下指令:
4446

45-
自动配置操作会自动插入 Native 代码(iOS 中使用 Appdelegate.m 文件名,如果修改了该文件名需要手动插入[代码](documents/ios_usage.md)),这个部分用户无需关系具体细节。
47+
```
48+
pod install
49+
```
4650

4751
### 2.手动操作部分(自动配置后,部分操作需要手动修改)
4852

documents/api.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [getLaunchAppNotification](#getlaunchappnotification)
2525
* [点击推送启动应用事件](#open-notification-launch-app-event)
2626
* [网络成功登陆事件](#network-did-login-event)
27+
* [hasPermission](#haspermission)
2728
* [Android Only API](#android-only-api)
2829
* [crashLogOFF](#crashlogoff)
2930
* [crashLogON](#crashlogno)
@@ -336,6 +337,16 @@ JPushModule.getLaunchAppNotification( notification => {
336337
})
337338
```
338339

340+
#### hasPermission
341+
342+
获取应用是否有推送权限。
343+
344+
```
345+
JPushModule.hasPermission( res => {
346+
// res = boolen
347+
})
348+
```
349+
339350
#### 点击推送启动应用事件
340351

341352
**NOTE**: iOS 需要安装到 [email protected]+ 。

example/App.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export default class App extends Component {
6767
console.log('Stop push press')
6868
}
6969

70+
onHasPermission () {
71+
JPushModule.hasPermission( res => console.log(`onHasPermission ${res}`) )
72+
}
73+
7074
onResumePress () {
7175
JPushModule.resumePush()
7276
console.log('Resume push press')
@@ -286,6 +290,14 @@ export default class App extends Component {
286290
>
287291
<Text style={styles.btnTextStyle}>STOPPUSH</Text>
288292
</TouchableHighlight>
293+
<TouchableHighlight
294+
underlayColor='#e4083f'
295+
activeOpacity={0.5}
296+
style={styles.btnStyle}
297+
onPress={this.onHasPermission}
298+
>
299+
<Text style={styles.btnTextStyle}>HasPermission</Text>
300+
</TouchableHighlight>
289301
<TouchableHighlight
290302
underlayColor='#f5a402'
291303
activeOpacity={0.5}

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ declare class JPush {
6060
*/
6161
static getConnectionState(cb: JResultCallback<boolean>): void
6262

63+
/**
64+
* iOS Only
65+
* 获取应用是否有推送权限
66+
*/
67+
static hasPermission(cb: JResultCallback<boolean>): void
6368
/**
6469
* 重新设置 Tag
6570
*/

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ export default class JPush {
3535
JPushModule.stopPush()
3636
}
3737

38+
39+
40+
/**
41+
* iOS Only
42+
* 判断是否成功授权推送(或是否在设置中成功开启推送功能)
43+
*
44+
* @param {Function} cb
45+
*/
46+
static hasPermission (cb) {
47+
if (Platform.OS == "ios") {
48+
JPushModule.hasPermission(res => {
49+
cb(res)
50+
})
51+
}
52+
}
53+
3854
/**
3955
* 恢复推送功能,停止推送后,可调用该方法重新获得推送能力
4056
*/

ios/RCTJPushModule/RCTJPushModule.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,38 @@ - (void)setBridge:(RCTBridge *)bridge {
149149
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
150150
}
151151

152+
RCT_EXPORT_METHOD(hasPermission:(RCTResponseSenderBlock)callback) {
153+
float systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
154+
155+
156+
if (systemVersion >= 8.0) {
157+
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
158+
UIUserNotificationType type = settings.types;
159+
if (type == UIUserNotificationTypeNone) {
160+
callback(@[@(NO)]);
161+
} else {
162+
callback(@[@(YES)]);
163+
}
164+
165+
} else if (systemVersion >= 10.0) {
166+
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
167+
168+
switch (settings.authorizationStatus)
169+
{
170+
case UNAuthorizationStatusDenied:
171+
case UNAuthorizationStatusNotDetermined:
172+
callback(@[@(NO)]);
173+
break;
174+
case UNAuthorizationStatusAuthorized:
175+
callback(@[@(YES)]);
176+
break;
177+
}
178+
}];
179+
}
180+
181+
182+
}
183+
152184
RCT_EXPORT_METHOD(getLaunchAppNotification:(RCTResponseSenderBlock)callback) {
153185
NSDictionary *notification;
154186
if ([RCTJPushActionQueue sharedInstance].openedRemoteNotification != nil) {

0 commit comments

Comments
 (0)