File tree Expand file tree Collapse file tree 5 files changed +66
-1
lines changed
Expand file tree Collapse file tree 5 files changed +66
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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+
152184RCT_EXPORT_METHOD (getLaunchAppNotification:(RCTResponseSenderBlock)callback) {
153185 NSDictionary *notification;
154186 if ([RCTJPushActionQueue sharedInstance ].openedRemoteNotification != nil ) {
Original file line number Diff line number Diff line change 11{
22 "name" : " jpush-react-native" ,
3- "version" : " 2.2.10 " ,
3+ "version" : " 2.2.11 " ,
44 "description" : " a jpush plugin for react native application" ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments