From 9ca61b40d8e8f1d7d99953c5893f48a338b85f2a Mon Sep 17 00:00:00 2001 From: Liuyf Date: Sat, 22 Feb 2025 15:43:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EiOS=20token=E6=88=AA?= =?UTF-8?q?=E5=8F=96=EF=BC=8C=E5=B9=B6=E5=9B=9E=E8=B0=83=E5=88=B0flutter?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jiguang/jpush/JPushHelper.java | 12 ++++++------ ios/Classes/JPushPlugin.m | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/jiguang/jpush/JPushHelper.java b/android/src/main/java/com/jiguang/jpush/JPushHelper.java index e888095..17a4ac9 100644 --- a/android/src/main/java/com/jiguang/jpush/JPushHelper.java +++ b/android/src/main/java/com/jiguang/jpush/JPushHelper.java @@ -197,12 +197,12 @@ public class JPushHelper { Log.d(TAG, "the channel is null"); return; } - Map notification = new HashMap<>(); - notification.put("cmd", cmdMessage.cmd); - notification.put("errorCode", cmdMessage.errorCode); - notification.put("msg", cmdMessage.msg); - notification.put("extras", bundleToMap(cmdMessage.extra)); - channel.invokeMethod("onCommandResult", notification); +// Map notification = new HashMap<>(); +// notification.put("cmd", cmdMessage.cmd); +// notification.put("errorCode", cmdMessage.errorCode); +// notification.put("msg", cmdMessage.msg); +// notification.put("extras", bundleToMap(cmdMessage.extra)); + channel.invokeMethod("onCommandResult", bundleToMap(cmdMessage.extra)); } public void onNotifyMessageUnShow(NotificationMessage notificationMessage) { diff --git a/ios/Classes/JPushPlugin.m b/ios/Classes/JPushPlugin.m index 6e4ed8f..e6bca21 100644 --- a/ios/Classes/JPushPlugin.m +++ b/ios/Classes/JPushPlugin.m @@ -620,9 +620,27 @@ static NSMutableArray* getRidResults; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + NSDictionary *tokenInfo = @{ + @"code" : @0, + @"cmd" : @100, + @"token" : [self hexStringFromData:deviceToken], + @"platform" : @7, + }; + [_channel invokeMethod:@"onCommandResult" arguments:tokenInfo]; [JPUSHService registerDeviceToken:deviceToken]; } +- (NSString *)hexStringFromData:(NSData *)data { + const unsigned char *dataBuffer = (const unsigned char *)[data bytes]; + NSMutableString *hexString = [NSMutableString stringWithCapacity:data.length * 2]; + + for (NSInteger i = 0; i < data.length; i++) { + [hexString appendFormat:@"%02x", dataBuffer[i]]; + } + + return [hexString copy]; +} + - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { NSDictionary *settingsDictionary = @{ @"sound" : [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeSound],