浏览代码

修改android bug

a289459798 8 年之前
父节点
当前提交
d0468dd06b

+ 13 - 13
README.md

@@ -2,7 +2,7 @@
 
 该项目基于小米推送,使用前,请先在小米开发者后台注册app,并获取对应的appid与appkey。
 
-开发环:xcode8、react-native 0.35
+开发环:xcode8、react-native 0.35
 
 ##作者
 
@@ -13,15 +13,15 @@ QQ群: 161263093
 
 ##安装
 
-==暂未上传到npm,待更新==
+npm install react-native-xmpush --save
 
 ##android
 
 打开`android`工程,`settings.gradle`,增加代码:
 
 ```
-include ':react-native-mipush'
-project(':react-native-mipush').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mipush/android')
+include ':react-native-xmpush'
+project(':react-native-xmpush').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-xmpush/android')
 
 ```
 修改`app`下面的的`build.gradle`,在`dependencies`区块下增加代码:
@@ -29,7 +29,7 @@ project(':react-native-mipush').projectDir = new File(rootProject.projectDir, '.
 ```
 dependencies {
     ...
-    compile project(':react-native-mipush')
+    compile project(':react-native-xmpush')
 }
 ```
 修改`MainApplication`文件,修改`getPackages`方法,添加`MIPushPackage`:
@@ -88,7 +88,7 @@ ios需要先制作推送证书,具体教程请自行百度。
 
 在targets->Build Settings下面搜索 Header Search Paths,添加
 
-> $(SRCROOT)/../node_modules/react-native-mipush/ios/MIPushModule
+> $(SRCROOT)/../node_modules/react-native-xmpush/ios/RCTMIPushModule
 >
 > $(SRCROOT)/../node_modules/react-native/Libraries/PushNotificationIOS
 
@@ -116,44 +116,44 @@ ios需要先制作推送证书,具体教程请自行百度。
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
 	...
-  	[MIPushModule application:application didFinishLaunchingWithOptions:launchOptions];
+  	[RCTMIPushModule application:application didFinishLaunchingWithOptions:launchOptions];
     ...
 }
 
 - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
 {
 
-  [MIPushModule application:application didRegisterUserNotificationSettings:notificationSettings];
+  [RCTMIPushModule application:application didRegisterUserNotificationSettings:notificationSettings];
   ...
 }
 
 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
 {
-  [MIPushModule application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+  [RCTMIPushModule application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
   ...
 }
 
 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
 {
-  [MIPushModule application:application didReceiveRemoteNotification:notification];
+  [RCTMIPushModule application:application didReceiveRemoteNotification:notification];
   ...
 }
 
 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
-  [MIPushModule application:application didReceiveLocalNotification:notification];
+  [RCTMIPushModule application:application didReceiveLocalNotification:notification];
   ...
 }
 
 // ios 10
 // 应用在前台收到通知
 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
-  [MIPushModule userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
+  [RCTMIPushModule userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
   ...
 }
 
 // 点击通知进入应用
 - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
-  [MIPushModule userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+  [RCTMIPushModule userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
   ....
   completionHandler();
 }

+ 0 - 3
android/src/main/java/com/ichong/zzy/mipush/MIPushPackage.java

@@ -29,9 +29,6 @@ public class MIPushPackage implements ReactPackage {
     public static ReactApplicationContext sReactContext;
     public static MiPushMessage sMiPushMessage;
 
-
-
-
     @Override
     public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
 

+ 11 - 2
android/src/main/java/com/ichong/zzy/mipush/MIPushReceiver.java

@@ -35,6 +35,7 @@ public class MIPushReceiver extends PushMessageReceiver {
 
         Intent intent = new Intent();
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
         if(MIPushPackage.sReactContext == null) {
             // 将数据保存
             MIPushPackage.sMiPushMessage = miPushMessage;
@@ -47,8 +48,16 @@ public class MIPushReceiver extends PushMessageReceiver {
         }
         sendListener("xmpush_click", miPushMessage);
 
-        intent.setClass(context, MIPushPackage.sReactContext.getCurrentActivity().getClass());
-        context.startActivity(intent);
+        if(MIPushPackage.sReactContext.getCurrentActivity() != null) {
+
+            intent.setClass(context, MIPushPackage.sReactContext.getCurrentActivity().getClass());
+            context.startActivity(intent);
+        } else {
+
+            String packageName = context.getApplicationContext().getPackageName();
+            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
+            context.startActivity(launchIntent);
+        }
 
     }
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "react-native-xmpush",
-  "version": "0.1.0",
+  "version": "0.1.1",
   "description": "集成小米推送",
   "main": "index.js",
   "scripts": {