Browse Source

兼容0.6+

zhangzy 5 years ago
parent
commit
74d5f95c3f

+ 2 - 2
XMPush.podspec

@@ -13,8 +13,8 @@ Pod::Spec.new do |s|
   s.ios.deployment_target = '9.0'
 
   s.source          = { :git => "https://github.com/a289459798/react-native-mipush", :tag => "v#{s.version}" }
-  s.source_files    = 'ios/RCTMIPushModule/RCTMIPushModule/*.{h,m}'
-  s.ios.vendored_libraries = 'ios/RCTMIPushModule/RCTMIPushModule/*.a'
+  s.source_files    = 'ios/*.{h,m}'
+  s.ios.vendored_libraries = 'ios/*.a'
   s.preserve_paths  = "**/*.js"
 
   s.dependency 'React'

BIN
android/libs/MiPush_SDK_Client_3_0_3.jar


BIN
android/libs/MiPush_SDK_Client_3_7_0.jar


+ 14 - 1
android/src/main/AndroidManifest.xml

@@ -1,29 +1,42 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.ichong.zzy.mipush">
+          package="com.ichong.zzy.mipush">
 
     <application>
 
         <service android:enabled="true" android:process=":pushservice"
                  android:name="com.xiaomi.push.service.XMPushService"/>
+
         <service android:name="com.xiaomi.push.service.XMJobService" android:enabled="true" android:exported="false"
                  android:permission="android.permission.BIND_JOB_SERVICE"
                  android:process=":pushservice"/> <!--注:此service必须在3.0.1版本以后(包括3.0.1版本)加入-->
+
         <service android:enabled="true" android:exported="true"
                  android:name="com.xiaomi.mipush.sdk.PushMessageHandler"/>
+
         <service android:enabled="true"
                  android:name="com.xiaomi.mipush.sdk.MessageHandleService"/> <!--注:此service必须在2.2.5版本以后(包括2.2.5版本)加入-->
         <receiver android:exported="true" android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver">
+
             <intent-filter>
+
                 <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
+
                 <category android:name="android.intent.category.DEFAULT"/>
+
             </intent-filter>
+
         </receiver>
+
         <receiver android:exported="false" android:process=":pushservice"
                   android:name="com.xiaomi.push.service.receivers.PingReceiver">
+
             <intent-filter>
+
                 <action android:name="com.xiaomi.push.PING_TIMER"/>
+
             </intent-filter>
+
         </receiver>
 
         <receiver

+ 18 - 4
index.js

@@ -31,13 +31,27 @@ class MIPush extends NativeEventEmitter {
         if (Platform.OS == 'android') {
             PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE).then((state) => {
                 if (state) {
-                    MIPushModule.init(appid, appkey);
-                } else {
-                    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE).then((granted) => {
-                        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
+                    PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE).then((state) => {
+                        if (state) {
+
                             MIPushModule.init(appid, appkey);
+                        } else {
+                            PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE).then((granted) => {
+                                if (granted === PermissionsAndroid.RESULTS.GRANTED) {
+                                    MIPushModule.init(appid, appkey);
+                                }
+                            });
                         }
                     });
+                } else {
+                    PermissionsAndroid.requestMultiple([
+                        PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE,
+                        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
+                    ]).then((granted) => {
+                        // if (granted === PermissionsAndroid.RESULTS.GRANTED) {
+                        MIPushModule.init(appid, appkey);
+                        // }
+                    });
                 }
             });
         }

+ 15 - 0
ios/MiPushApnsAckSDK.h

@@ -0,0 +1,15 @@
+//
+//  MiPushNotificationServiceSDK.h
+//  MiPushNotificationServiceSDK
+//
+//  Created by zzl on 2019/10/14.
+//  Copyright © 2019 Xiaomi. All rights reserved.
+//
+
+#import <UserNotifications/UserNotifications.h>
+
+@interface MiPushApnsAckSDK : NSObject
+
++ (void)reportApnsAck:(NSDictionary *)userInfo;
+
+@end

+ 59 - 1
ios/RCTMIPushModule/RCTMIPushModule/MiPushSDK.h

@@ -36,10 +36,46 @@
  */
 - (void)miPushReceiveNotification:(NSDictionary*)data;
 
+/**
+ * 长连接状态变化回调
+ * 网络环境变化,或长连接异常才会触发offline
+ * 应用前后台切换,不会触发回调
+ */
+- (void)miPushConnectionOnline;
+- (void)miPushConnectionOffline;
+
+
 @end
 
+typedef NS_ENUM(NSUInteger, MiPushSDKRegionType) {
+    MiPushSDKRegionTypeChina = 0,
+    MiPushSDKRegionTypeEurope,
+    MiPushSDKRegionTypeRussia,
+    MiPushSDKRegionTypeOther,
+};
+
 @interface MiPushSDK : NSObject
 
+
+/**
+ * 设置 RegionType
+ * @param
+ *     MiPushSDKRegionType: region 类型,目前支持中国/欧洲/新加坡
+ */
++ (void)setRegionType:(MiPushSDKRegionType)regionType;
+
+/**
+ * 获取当前 RegionType
+ */
+
++ (MiPushSDKRegionType)getRegionType;
+
+/**
+ * 获取当前 RegionType 对应的 string
+ */
+
++ (NSString *)getRegion;
+
 /**
  * 客户端注册设备
  * @param 
@@ -56,6 +92,15 @@
  */
 + (void)unregisterMiPush;
 
+/**
+ *
+ * 配置是否在后台需要长连接,如果需要长连接,需要保证在后台app仍处于活跃状态
+ * @param
+ *      enable: 是否需要长连接
+ *
+ */
++ (void)needConnectInBackground:(BOOL)enable;
+
 
 /**
  * 绑定 PushDeviceToken
@@ -136,7 +181,7 @@
  * @param 
  *      messageId:Payload里面对应的miid参数
  */
-+ (void)openAppNotify:(NSString *)messageId;
++ (void)openAppNotify:(NSString *)messageId __deprecated;
 
 
 /**
@@ -174,4 +219,17 @@
  * 如果没有RegId返回nil
  */
 + (NSString*)getRegId;
+
+/**
+ * 设置自定义bundle path
+ * 默认为nil,获取当前SDK所在的bundle路径
+ */
++ (void)setBundlePath:(NSString *)path;
+
+/**
+ * 获取自定义bundle path
+ * 如果没有返回nil
+ */
++ (NSString*)getBundlePath;
+
 @end

ios/RCTMIPushModule/RCTMIPushModule/RCTMIPushModule.h → ios/RCTMIPushModule.h


ios/RCTMIPushModule/RCTMIPushModule/RCTMIPushModule.m → ios/RCTMIPushModule.m


ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/project.pbxproj → ios/RCTMIPushModule.xcodeproj/project.pbxproj


ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata → ios/RCTMIPushModule.xcodeproj/project.xcworkspace/contents.xcworkspacedata


ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/project.xcworkspace/xcuserdata/zhangzy.xcuserdatad/UserInterfaceState.xcuserstate → ios/RCTMIPushModule.xcodeproj/project.xcworkspace/xcuserdata/zhangzy.xcuserdatad/UserInterfaceState.xcuserstate


ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/xcuserdata/zhangzy.xcuserdatad/xcschemes/RCTMIPushModule.xcscheme → ios/RCTMIPushModule.xcodeproj/xcuserdata/zhangzy.xcuserdatad/xcschemes/RCTMIPushModule.xcscheme


ios/RCTMIPushModule/RCTMIPushModule.xcodeproj/xcuserdata/zhangzy.xcuserdatad/xcschemes/xcschememanagement.plist → ios/RCTMIPushModule.xcodeproj/xcuserdata/zhangzy.xcuserdatad/xcschemes/xcschememanagement.plist


BIN
ios/libMiPushApnsAckSDK.a


BIN
ios/RCTMIPushModule/RCTMIPushModule/libMiPushSDK.a