Bladeren bron

部分补充

linbing 5 jaren geleden
bovenliggende
commit
d92d3195f8
2 gewijzigde bestanden met toevoegingen van 26 en 0 verwijderingen
  1. 4 0
      example/lib/main.dart
  2. 22 0
      lib/flutter_aliyun_push.dart

+ 4 - 0
example/lib/main.dart

@@ -38,6 +38,10 @@ class _MyAppState extends State<MyApp> {
       platformVersion = msg;
     });
 
+    FlutterAliyunPush.reigistOnReceiveNotification((msg){
+      platformVersion = msg.title;
+    });
+
     // If the widget was removed from the tree while the asynchronous platform
     // message was in flight, we want to discard the reply rather than calling
     // setState to update our non-existent appearance.

+ 22 - 0
lib/flutter_aliyun_push.dart

@@ -9,6 +9,8 @@ class FlutterAliyunPush {
 
   static Function onRegistSuccess;
   static Function onRegistError;
+  static Function onReceiveNotification;
+  static Function onReceiveMessage;
 
   static Future<String> get platformVersion async {
     final String version = await _channel.invokeMethod('getPlatformVersion');
@@ -41,6 +43,16 @@ class FlutterAliyunPush {
             onRegistError(call.arguments);
           }
           break;
+        case "onReceiverNotification":
+          if(onReceiveNotification != null) {
+            onReceiveNotification(call.arguments);
+          }
+          break;
+        case "onReceiverMessage":
+          if(onReceiveMessage != null) {
+            onReceiveMessage(call.arguments);
+          }
+          break;
       }
     });
   }
@@ -55,6 +67,16 @@ class FlutterAliyunPush {
     onRegistError = callback;
     registCallHandler();
   }
+
+  static void  reigistOnReceiveNotification(Function callback) {
+    onReceiveNotification = callback;
+    registCallHandler();
+  }
+
+  static void  reigistOnReceiveMessage(Function callback) {
+    onReceiveMessage = callback;
+    registCallHandler();
+  }
 }