diff --git a/.packages b/.packages index 7ad6ec9..6368a38 100644 --- a/.packages +++ b/.packages @@ -1,4 +1,4 @@ -# Generated by pub on 2019-08-23 15:35:48.440553. +# Generated by pub on 2019-09-25 15:21:45.301321. analyzer:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/analyzer-0.37.0/lib/ args:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/args-1.5.2/lib/ async:file:///Applications/flutter/.pub-cache/hosted/pub.flutter-io.cn/async-2.3.0/lib/ diff --git a/CHANGELOG.md b/CHANGELOG.md index c75dfea..2771b1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.2.0 ++ 适配最新版本 JPush SDK ++ Android 支持设置角标 badge ## 0.1.0 + 修复:调用 sendLocalNotification 接口 crash 问题; + 修复:iOS 启动 APP 角标自动消失问题; diff --git a/README.md b/README.md index 66c79a4..b83dd6d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,14 @@ ```yaml dependencies: - jpush_flutter: 0.1.0 + jpush_flutter: 0.2.0 + +//github +dependencies: + jmessage_flutter: + git: + url: git://github.com/jpush/jmessage-flutter-plugin.git + ref: master ``` ### 配置 diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index be92956..6679a91 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -34,4 +34,5 @@ + diff --git a/android/src/main/java/com/jiguang/jpush/JPushPlugin.java b/android/src/main/java/com/jiguang/jpush/JPushPlugin.java index 511cb48..aff313c 100644 --- a/android/src/main/java/com/jiguang/jpush/JPushPlugin.java +++ b/android/src/main/java/com/jiguang/jpush/JPushPlugin.java @@ -33,6 +33,7 @@ public class JPushPlugin implements MethodCallHandler { } + private static String TAG = "| JPUSH | Android | "; public static JPushPlugin instance; static List> openNotificationCache = new ArrayList<>(); @@ -60,6 +61,7 @@ public class JPushPlugin implements MethodCallHandler { @Override public void onMethodCall(MethodCall call, Result result) { + Log.i(TAG,call.method); if (call.method.equals("getPlatformVersion")) { result.success("Android " + android.os.Build.VERSION.RELEASE); } else if (call.method.equals("setup")) { @@ -90,12 +92,17 @@ public class JPushPlugin implements MethodCallHandler { getRegistrationID(call, result); } else if (call.method.equals("sendLocalNotification")) { sendLocalNotification(call, result); - } else { + } else if (call.method.equals("setBadge")) { + setBadge(call, result); + } + else { result.notImplemented(); } } public void setup(MethodCall call, Result result) { + Log.d(TAG,"setup :" + call.arguments); + HashMap map = call.arguments(); boolean debug = (boolean)map.get("debug"); JPushInterface.setDebugMode(debug); @@ -112,6 +119,8 @@ public class JPushPlugin implements MethodCallHandler { } public void scheduleCache() { + Log.d(TAG,"scheduleCache:"); + if (dartIsReady) { // try to shedule notifcation cache for (Map notification: JPushPlugin.openNotificationCache) { @@ -131,6 +140,8 @@ public class JPushPlugin implements MethodCallHandler { } public void setTags(MethodCall call, Result result) { + Log.d(TAG,"setTags:"); + ListtagList = call.arguments(); Set tags = new HashSet<>(tagList); sequence += 1; @@ -139,12 +150,16 @@ public class JPushPlugin implements MethodCallHandler { } public void cleanTags(MethodCall call, Result result) { + Log.d(TAG,"cleanTags:"); + sequence += 1; callbackMap.put(sequence, result); JPushInterface.cleanTags(registrar.context(), sequence); } public void addTags(MethodCall call, Result result) { + Log.d(TAG,"addTags: " + call.arguments); + ListtagList = call.arguments(); Set tags = new HashSet<>(tagList); sequence += 1; @@ -153,6 +168,8 @@ public class JPushPlugin implements MethodCallHandler { } public void deleteTags(MethodCall call, Result result) { + Log.d(TAG,"deleteTags: " + call.arguments); + ListtagList = call.arguments(); Set tags = new HashSet<>(tagList); sequence += 1; @@ -161,12 +178,16 @@ public class JPushPlugin implements MethodCallHandler { } public void getAllTags(MethodCall call, Result result) { + Log.d(TAG,"getAllTags: "); + sequence += 1; callbackMap.put(sequence, result); JPushInterface.getAllTags(registrar.context(), sequence); } public void setAlias(MethodCall call, Result result) { + Log.d(TAG,"setAlias: " + call.arguments); + String alias= call.arguments(); sequence += 1; callbackMap.put(sequence, result); @@ -174,6 +195,8 @@ public class JPushPlugin implements MethodCallHandler { } public void deleteAlias(MethodCall call, Result result) { + Log.d(TAG,"deleteAlias:"); + String alias= call.arguments(); sequence += 1; callbackMap.put(sequence, result); @@ -181,22 +204,31 @@ public class JPushPlugin implements MethodCallHandler { } public void stopPush(MethodCall call, Result result) { + Log.d(TAG,"stopPush:"); + JPushInterface.stopPush(registrar.context()); } public void resumePush(MethodCall call, Result result) { + Log.d(TAG,"resumePush:"); + JPushInterface.resumePush(registrar.context()); } public void clearAllNotifications(MethodCall call, Result result) { + Log.d(TAG,"clearAllNotifications: "); + JPushInterface.clearAllNotifications(registrar.context()); } public void getLaunchAppNotification(MethodCall call, Result result) { + Log.d(TAG,""); + } public void getRegistrationID(MethodCall call, Result result) { + Log.d(TAG,"getRegistrationID: "); String rid = JPushInterface.getRegistrationID(registrar.context()); if (rid == null || rid.isEmpty()) { @@ -208,6 +240,8 @@ public class JPushPlugin implements MethodCallHandler { public void sendLocalNotification(MethodCall call, Result result) { + Log.d(TAG,"sendLocalNotification: " + call.arguments); + try { HashMap map = call.arguments(); @@ -232,6 +266,17 @@ public class JPushPlugin implements MethodCallHandler { } } + public void setBadge(MethodCall call, Result result) { + Log.d(TAG,"setBadge: " + call.arguments); + + HashMap map = call.arguments(); + Object numObject = map.get("badge"); + if (numObject != null) { + int num = (int)numObject; + JPushInterface.setBadgeNumber(registrar.context(),num); + result.success(true); + } + } /** * 接收自定义消息,通知,通知点击事件等事件的广播 @@ -248,6 +293,7 @@ public class JPushPlugin implements MethodCallHandler { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); + if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) { String rId = intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID); Log.d("JPushPlugin","on get registration"); @@ -264,12 +310,16 @@ public class JPushPlugin implements MethodCallHandler { } private void handlingMessageReceive(Intent intent) { + Log.d(TAG,"handlingMessageReceive " + intent.getAction()); + String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE); Map extras = getNotificationExtras(intent); JPushPlugin.transmitMessageReceive(msg, extras); } private void handlingNotificationOpen(Context context, Intent intent) { + Log.d(TAG,"handlingNotificationOpen " + intent.getAction()); + String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE); String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT); Map extras = getNotificationExtras(intent); @@ -284,6 +334,8 @@ public class JPushPlugin implements MethodCallHandler { } private void handlingNotificationReceive(Context context, Intent intent) { + Log.d(TAG,"handlingNotificationReceive " + intent.getAction()); + String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE); String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT); Map extras = getNotificationExtras(intent); @@ -291,6 +343,8 @@ public class JPushPlugin implements MethodCallHandler { } private Map getNotificationExtras(Intent intent) { + Log.d(TAG,""); + Map extrasMap = new HashMap(); for (String key : intent.getExtras().keySet()) { if (!IGNORED_EXTRAS_KEYS.contains(key)) { @@ -307,6 +361,8 @@ public class JPushPlugin implements MethodCallHandler { static void transmitMessageReceive(String message, Map extras) { + Log.d(TAG,"transmitMessageReceive " + "message=" + message + "extras=" + extras); + if (instance == null) { return; } @@ -318,6 +374,8 @@ public class JPushPlugin implements MethodCallHandler { } static void transmitNotificationOpen(String title, String alert, Map extras) { + Log.d(TAG,"transmitNotificationOpen " + "title=" + title + "alert=" + alert + "extras=" + extras); + Map notification= new HashMap<>(); notification.put("title", title); notification.put("alert", alert); @@ -338,6 +396,8 @@ public class JPushPlugin implements MethodCallHandler { } static void transmitNotificationReceive(String title, String alert, Map extras) { + Log.d(TAG,"transmitNotificationReceive " + "title=" + title + "alert=" + alert + "extras=" + extras); + if (instance == null) { return; } @@ -350,6 +410,8 @@ public class JPushPlugin implements MethodCallHandler { } static void transmitReceiveRegistrationId(String rId) { + Log.d(TAG,"transmitReceiveRegistrationId: " + rId); + if (instance == null) { return; } diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index f04deb8..e4449cb 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 342565195A7B02408C258C63 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E8558CD656C3CFECC78ECB83 /* libPods-Runner.a */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; @@ -41,7 +40,7 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; + 243DB7546D048251A9867C1C /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 625494FA213F7D30005E4423 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; @@ -57,6 +56,7 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C3EB3B32DF8D367805D86460 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; E8558CD656C3CFECC78ECB83 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -85,7 +85,6 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -143,6 +142,8 @@ AB735DD26662031199114838 /* Pods */ = { isa = PBXGroup; children = ( + 243DB7546D048251A9867C1C /* Pods-Runner.debug.xcconfig */, + C3EB3B32DF8D367805D86460 /* Pods-Runner.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -183,7 +184,7 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = RL64Y54S9V; + ProvisioningStyle = Manual; SystemCapabilities = { com.apple.ApplePay = { enabled = 0; @@ -203,6 +204,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -225,7 +227,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -239,16 +240,13 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { @@ -440,8 +438,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = RL64Y54S9V; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -453,8 +453,9 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.huminios.jpushTest; + PRODUCT_BUNDLE_IDENTIFIER = com.jpush.test; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -465,8 +466,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; + CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = RL64Y54S9V; + DEVELOPMENT_TEAM = ""; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -478,8 +481,9 @@ "$(inherited)", "$(PROJECT_DIR)/Flutter", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.huminios.jpushTest; + PRODUCT_BUNDLE_IDENTIFIER = com.jpush.test; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; diff --git a/example/pubspec.lock b/example/pubspec.lock index 04b65dc..47bdf62 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -136,7 +136,7 @@ packages: path: ".." relative: true source: path - version: "0.1.0" + version: "0.2.0" js: dependency: transitive description: diff --git a/ios/Classes/JPushPlugin.m b/ios/Classes/JPushPlugin.m index 1ded726..be88491 100644 --- a/ios/Classes/JPushPlugin.m +++ b/ios/Classes/JPushPlugin.m @@ -5,6 +5,8 @@ #import +#define JPLog(fmt, ...) NSLog((@"| JPUSH | iOS | " fmt), ##__VA_ARGS__) + @interface NSError (FlutterError) @property(readonly, nonatomic) FlutterError *flutterError; @end @@ -111,6 +113,8 @@ static NSMutableArray* getRidResults; } - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"handleMethodCall:%@",call.method); + if ([@"getPlatformVersion" isEqualToString:call.method]) { result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]); } else if([@"setup" isEqualToString:call.method]) { @@ -153,6 +157,7 @@ static NSMutableArray* getRidResults; - (void)setup:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"setup:"); NSDictionary *arguments = call.arguments; NSNumber *debug = arguments[@"debug"]; if ([debug boolValue]) { @@ -168,6 +173,7 @@ static NSMutableArray* getRidResults; } - (void)applyPushAuthority:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"applyPushAuthority:%@",call.arguments); notificationTypes = 0; NSDictionary *arguments = call.arguments; if ([arguments[@"sound"] boolValue]) { @@ -185,6 +191,7 @@ static NSMutableArray* getRidResults; } - (void)setTags:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"setTags:%@",call.arguments); NSSet *tagSet; if (call.arguments != NULL) { @@ -202,6 +209,7 @@ static NSMutableArray* getRidResults; } - (void)cleanTags:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"cleanTags:"); [JPUSHService cleanTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { if (iResCode == 0) { result(@{@"tags": iTags ? [iTags allObjects] : @[]}); @@ -213,6 +221,7 @@ static NSMutableArray* getRidResults; } - (void)addTags:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"addTags:%@",call.arguments); NSSet *tagSet; if (call.arguments != NULL) { @@ -230,6 +239,7 @@ static NSMutableArray* getRidResults; } - (void)deleteTags:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"deleteTags:%@",call.arguments); NSSet *tagSet; if (call.arguments != NULL) { @@ -247,6 +257,7 @@ static NSMutableArray* getRidResults; } - (void)getAllTags:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"getAllTags:"); [JPUSHService getAllTags:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) { if (iResCode == 0) { result(@{@"tags": iTags ? [iTags allObjects] : @[]}); @@ -258,6 +269,7 @@ static NSMutableArray* getRidResults; } - (void)setAlias:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"setAlias:%@",call.arguments); NSString *alias = call.arguments; [JPUSHService setAlias:alias completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { if (iResCode == 0) { @@ -270,6 +282,7 @@ static NSMutableArray* getRidResults; } - (void)deleteAlias:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"deleteAlias:%@",call.arguments); [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { if (iResCode == 0) { result(@{@"alias": iAlias ?: @""}); @@ -281,24 +294,32 @@ static NSMutableArray* getRidResults; } - (void)setBadge:(FlutterMethodCall*)call result:(FlutterResult)result { - NSNumber *badge = call.arguments; - [[UIApplication sharedApplication] setApplicationIconBadgeNumber: badge.integerValue]; - [JPUSHService setBadge: badge.integerValue > 0 ? badge.integerValue: 0]; + JPLog(@"setBadge:%@",call.arguments); + NSInteger badge = [call.arguments[@"badge"] integerValue]; + if (badge < 0) { + badge = 0; + } + [[UIApplication sharedApplication] setApplicationIconBadgeNumber: badge]; + [JPUSHService setBadge: badge]; } - (void)stopPush:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"stopPush:"); [[UIApplication sharedApplication] unregisterForRemoteNotifications]; } - (void)clearAllNotifications:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"clearAllNotifications:"); [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; } - (void)getLaunchAppNotification:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"getLaunchAppNotification"); result(_launchNotification == nil ? @{}: _launchNotification); } - (void)getRegistrationID:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"getRegistrationID:"); #if TARGET_IPHONE_SIMULATOR//模拟器 NSLog(@"simulator can not get registrationid"); result(@""); @@ -320,6 +341,7 @@ static NSMutableArray* getRidResults; } - (void)sendLocalNotification:(FlutterMethodCall*)call result:(FlutterResult)result { + JPLog(@"sendLocalNotification:%@",call.arguments); JPushNotificationContent *content = [[JPushNotificationContent alloc] init]; NSDictionary *params = call.arguments; if (params[@"title"]) { diff --git a/lib/jpush_flutter.dart b/lib/jpush_flutter.dart index 962551c..52e72c4 100644 --- a/lib/jpush_flutter.dart +++ b/lib/jpush_flutter.dart @@ -7,6 +7,7 @@ import 'package:platform/platform.dart'; typedef Future EventHandler(Map event); class JPush { + final String flutter_log = "| JPUSH | Flutter | "; factory JPush() => _instance; final MethodChannel _channel; @@ -31,6 +32,8 @@ class JPush { String channel = '', bool debug = false, }) { + print(flutter_log + "setup:"); + _channel.invokeMethod('setup', { 'appKey': appKey, 'channel': channel, 'production': production, 'debug': debug}); } /// @@ -41,6 +44,8 @@ class JPush { EventHandler onOpenNotification, EventHandler onReceiveMessage, }) { + print(flutter_log + "addEventHandler:"); + _onReceiveNotification = onReceiveNotification; _onOpenNotification = onOpenNotification; _onReceiveMessage = onReceiveMessage; @@ -48,6 +53,8 @@ class JPush { } Future _handleMethod(MethodCall call) async { + print(flutter_log + "_handleMethod:"); + switch (call.method) { case "onReceiveNotification": return _onReceiveNotification(call.arguments.cast()); @@ -64,8 +71,9 @@ class JPush { /// 申请推送权限,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。 /// void applyPushAuthority([NotificationSettingsIOS iosSettings = const NotificationSettingsIOS()]) { + print(flutter_log + "applyPushAuthority:"); - if (!_platform.isIOS) { + if (!_platform.isIOS) { return; } @@ -80,6 +88,8 @@ class JPush { /// @param {Function} fail = ({"errorCode":int}) => { } /// Future> setTags(List tags) async { + print(flutter_log + "setTags:"); + final Map result = await _channel.invokeMethod('setTags', tags); return result; } @@ -91,6 +101,8 @@ class JPush { /// @param {Function} fail = ({"errorCode":int}) => { } /// Future> cleanTags() async { + print(flutter_log + "cleanTags:"); + final Map result = await _channel.invokeMethod('cleanTags'); return result; } @@ -104,6 +116,8 @@ class JPush { /// Future> addTags(List tags) async { + print(flutter_log + "addTags:"); + final Map result = await _channel.invokeMethod('addTags', tags); return result; } @@ -116,6 +130,8 @@ class JPush { /// @param {Function} fail = ({"errorCode":int}) => { } /// Future> deleteTags(List tags) async { + print(flutter_log + "deleteTags:"); + final Map result = await _channel.invokeMethod('deleteTags', tags); return result; } @@ -127,6 +143,8 @@ class JPush { /// @param {Function} fail = ({"errorCode":int}) => { } /// Future> getAllTags() async { + print(flutter_log + "getAllTags:"); + final Map result = await _channel.invokeMethod('getAllTags'); return result; } @@ -140,6 +158,8 @@ class JPush { /// @param {Function} fail = ({"errorCode":int}) => { } /// Future> setAlias(String alias) async { + print(flutter_log + "setAlias:"); + final Map result = await _channel.invokeMethod('setAlias', alias); return result; } @@ -151,24 +171,31 @@ class JPush { /// @param {Function} fail = ({"errorCode":int}) => { } /// Future> deleteAlias() async { + print(flutter_log + "deleteAlias:"); + final Map result = await _channel.invokeMethod('deleteAlias'); return result; } /// - /// iOS Only /// 设置应用 Badge(小红点) /// /// @param {Int} badge /// + /// 注意:如果是 Android 手机,目前仅支持华为手机 + /// Future setBadge(int badge) async { - await _channel.invokeMethod('setBadge', badge); + print(flutter_log + "setBadge:"); + + await _channel.invokeMethod('setBadge', {"badge":badge}); } /// /// 停止接收推送,调用该方法后应用将不再受到推送,如果想要重新收到推送可以调用 resumePush。 /// Future stopPush() async { + print(flutter_log + "stopPush:"); + await _channel.invokeMethod('stopPush'); } @@ -176,6 +203,8 @@ class JPush { /// 恢复推送功能。 /// Future resumePush() async { + print(flutter_log + "resumePush:"); + await _channel.invokeMethod('resumePush'); } @@ -183,6 +212,8 @@ class JPush { /// 清空通知栏上的所有通知。 /// Future clearAllNotifications() async { + print(flutter_log + "clearAllNotifications:"); + await _channel.invokeMethod('clearAllNotifications'); } @@ -194,6 +225,8 @@ class JPush { /// @param {Function} callback = (Object) => {} /// Future> getLaunchAppNotification() async { + print(flutter_log + "getLaunchAppNotification:"); + final Map result = await _channel.invokeMethod('getLaunchAppNotification'); return result; } @@ -204,6 +237,8 @@ class JPush { /// @param {Function} callback = (String) => {} /// Future getRegistrationID() async { + print(flutter_log + "getRegistrationID:"); + final String rid = await _channel.invokeMethod('getRegistrationID'); return rid; } @@ -213,10 +248,13 @@ class JPush { /// @param {Notification} notification /// Future sendLocalNotification(LocalNotification notification) async { - await _channel.invokeMethod('sendLocalNotification', notification.toMap()); + print(flutter_log + "sendLocalNotification:"); + + await _channel.invokeMethod('sendLocalNotification', notification.toMap()); return notification.toMap().toString(); } + } class NotificationSettingsIOS { diff --git a/pubspec.yaml b/pubspec.yaml index 0be7aa9..88c31b6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: jpush_flutter description: Offically supported JPush Flutter plugin. -version: 0.1.0 +version: 0.2.0 author: huminios homepage: https://www.jiguang.cn