Merge branch 'develop_liyi' into canary_release

This commit is contained in:
Liuyf 2025-02-13 10:58:11 +08:00
commit f65226d7e2
5 changed files with 97 additions and 14 deletions

View File

@ -9,6 +9,7 @@
@interface AppDelegate() @interface AppDelegate()
@property (nonatomic, strong) FlutterMethodChannel *methodChannel;
@end @end
@ -21,6 +22,19 @@
// [UMConfigure initWithAppkey:@"671244ae80464b33f6df9646" channel:@"Product"]; // [UMConfigure initWithAppkey:@"671244ae80464b33f6df9646" channel:@"Product"];
//Required
//notice: 3.0.0
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
// categories
// NSSet<UNNotificationCategory *> *categories for iOS10 or later
// NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
}
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
XSFlutterManager *VC = [[XSFlutterManager alloc] init]; XSFlutterManager *VC = [[XSFlutterManager alloc] init];
self.window.rootViewController = VC; self.window.rootViewController = VC;
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
@ -64,7 +78,7 @@
*/ */
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//sdkDeviceToken /// Required - DeviceToken
[JPUSHService registerDeviceToken:deviceToken]; [JPUSHService registerDeviceToken:deviceToken];
} }
@ -72,7 +86,8 @@
* *
*/ */
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error); //Optional
NSLog(@"did Fail To Register For Remote Notifications With Error: %@", error);
} }
/** /**
@ -96,6 +111,49 @@
NSLog(@"Receive message title: %@, content: %@.", title, body); NSLog(@"Receive message title: %@, content: %@.", title, body);
} }
# pragma mark- JPUSHRegisterDelegate
// iOS 12 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification{
if (notification && [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
//
}else{
//
}
}
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
// Required
NSDictionary * userInfo = notification.request.content.userInfo;
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(UNNotificationPresentationOptionAlert); // BadgeSoundAlert
}
// iOS 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
// Required
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[JPUSHService handleRemoteNotification:userInfo];
}
completionHandler(); //
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Required, iOS 7 Support
[JPUSHService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// Required, For systems with less than or equal to iOS 6
[JPUSHService handleRemoteNotification:userInfo];
}

View File

@ -64,6 +64,7 @@
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) { activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (completed) { if (completed) {
NSLog(@"completed"); NSLog(@"completed");
// //
} else { } else {
NSLog(@"canceled"); NSLog(@"canceled");
@ -72,6 +73,10 @@
}; };
result(@"push返回到flutter"); result(@"push返回到flutter");
} }
if ([method isEqualToString:@"getBundleIdentifier"]) {
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
result(bundleIdentifier); // Bundle Identifier
}
}]; }];
[GeneratedPluginRegistrant registerWithRegistry:self]; [GeneratedPluginRegistrant registerWithRegistry:self];

View File

@ -14,7 +14,6 @@ import 'package:star_lock/talk/starChart/proto/gateway_reset.pb.dart';
import 'package:star_lock/talk/starChart/proto/generic.pb.dart'; import 'package:star_lock/talk/starChart/proto/generic.pb.dart';
import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart'; import 'package:star_lock/talk/starChart/proto/talk_expect.pb.dart';
import 'package:star_lock/talk/starChart/proto/talk_request.pb.dart'; import 'package:star_lock/talk/starChart/proto/talk_request.pb.dart';
import 'package:star_lock/tools/push/xs_jPhush.dart';
import 'package:star_lock/tools/storage.dart'; import 'package:star_lock/tools/storage.dart';
class UdpTalkRequestHandler extends ScpMessageBaseHandle class UdpTalkRequestHandler extends ScpMessageBaseHandle
@ -79,7 +78,9 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
// //
Future<void> _showTalkRequestNotification( Future<void> _showTalkRequestNotification(
{required String talkObjectName}) async { {required String talkObjectName}) async {
final Map<String, dynamic> message = { /**
*
final Map<String, dynamic> message = {
'platform': 'all', 'platform': 'all',
'audience': 'all', 'audience': 'all',
'notification': <String, Map<String, Object>>{ 'notification': <String, Map<String, Object>>{
@ -95,8 +96,7 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
}; };
XSJPushProvider().showCustomNotification(message); XSJPushProvider().showCustomNotification(message);
*/
/*
const AndroidNotificationDetails androidPlatformChannelSpecifics = const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails('1', 'flutter_channel', AndroidNotificationDetails('1', 'flutter_channel',
importance: Importance.max, importance: Importance.max,
@ -113,7 +113,6 @@ class UdpTalkRequestHandler extends ScpMessageBaseHandle
await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr, await flutterLocalNotificationsPlugin.show(0, '呼叫提醒'.tr,
'${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}', platformChannelSpecifics, '${'收到来自'.tr}($talkObjectName)${'锁的呼叫'.tr}', platformChannelSpecifics,
payload: 'item x'); payload: 'item x');
*/
} }
@override @override

View File

@ -1,5 +1,6 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:star_lock/flavors.dart'; import 'package:star_lock/flavors.dart';
import 'package:star_lock/tools/push/xs_jPhush.dart';
import '../app_settings/app_settings.dart'; import '../app_settings/app_settings.dart';
@ -52,4 +53,15 @@ class NativeInteractionTool {
} }
}); });
} }
Future<String?> getBundleIdentifier() async {
try {
final String? bundleIdentifier =
await sendChannel.invokeMethod('getBundleIdentifier');
return bundleIdentifier;
} on PlatformException catch (e) {
print("Failed to get bundle identifier: '${e.message}'.");
return null;
}
}
} }

View File

@ -1,11 +1,13 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:jpush_flutter/jpush_flutter.dart'; import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:star_lock/flavors.dart'; import 'package:star_lock/flavors.dart';
import 'package:star_lock/mine/minePersonInfo/minePersonInfoEditAccount/minePersonInfoEditAccount/mineUnbindPhoneOrEmail_entity.dart'; import 'package:star_lock/mine/minePersonInfo/minePersonInfoEditAccount/minePersonInfoEditAccount/mineUnbindPhoneOrEmail_entity.dart';
import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/tools/NativeInteractionTool.dart';
import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/baseGetXController.dart';
import 'package:star_lock/tools/push/message_management.dart'; import 'package:star_lock/tools/push/message_management.dart';
import 'package:star_lock/tools/push/notification_service.dart'; import 'package:star_lock/tools/push/notification_service.dart';
@ -15,7 +17,6 @@ import '../../app_settings/app_settings.dart';
class XSJPushProvider { class XSJPushProvider {
final JPush jpush = JPush(); final JPush jpush = JPush();
final NotificationService _notificationService = NotificationService();
// appKey: 251fc8074820d122b6de58d2--AppKey // appKey: 251fc8074820d122b6de58d2--AppKey
// appKey: 7ff37d174c1a568a89e98dad--sky // appKey: 7ff37d174c1a568a89e98dad--sky
@ -27,6 +28,9 @@ class XSJPushProvider {
} }
print('jPushKey ${F.jPushKey}'); print('jPushKey ${F.jPushKey}');
// final String? bundleIdentifier =
// await NativeInteractionTool().getBundleIdentifier();
// print('bundleIdentifier: $bundleIdentifier');
jpush.setup( jpush.setup(
appKey: F.jPushKey, appKey: F.jPushKey,
channel: 'flutter_channel', channel: 'flutter_channel',
@ -40,6 +44,10 @@ class XSJPushProvider {
addJPushEventHandler(); addJPushEventHandler();
AppLog.log('JPush initialized.'); AppLog.log('JPush initialized.');
final String rid = await jpush.getRegistrationID();
print('flutter get registration id : $rid');
pushBindDeviceID(rid);
} }
// //
@ -69,11 +77,13 @@ class XSJPushProvider {
final String rid = await jpush.getRegistrationID(); final String rid = await jpush.getRegistrationID();
AppLog.log('onConnected registration id : $rid'); AppLog.log('onConnected registration id : $rid');
await Storage.setString(pushDeviceID, rid); await Storage.setString(pushDeviceID, rid);
await pushBindDeviceID(rid, Platform.isAndroid ? 10 : 20); await pushBindDeviceID(rid);
return Future.value(); return Future.value();
}, },
); );
// Remove the incorrect addEventHandler call
} }
Future<void> showCustomNotification(Map<String, dynamic> message) async { Future<void> showCustomNotification(Map<String, dynamic> message) async {
@ -86,7 +96,7 @@ class XSJPushProvider {
NotificationService().showImageNotification(title, content, imageUrl); NotificationService().showImageNotification(title, content, imageUrl);
} }
Future<void> pushBindDeviceID(String deviceID, int deviceType) async { Future<void> pushBindDeviceID(String deviceID) async {
try { try {
if (deviceID.isEmpty) { if (deviceID.isEmpty) {
AppLog.log('Device ID is empty.'); AppLog.log('Device ID is empty.');
@ -95,10 +105,9 @@ class XSJPushProvider {
AppLog.log('onConnected registration id : $rid'); AppLog.log('onConnected registration id : $rid');
await Storage.setString(pushDeviceID, rid); await Storage.setString(pushDeviceID, rid);
deviceID = rid; deviceID = rid;
deviceType = Platform.isAndroid ? 10 : 20;
} }
final MineUnbindPhoneOrEmailEntity entity = final MineUnbindPhoneOrEmailEntity entity = await ApiRepository.to
await ApiRepository.to.pushBindAppId(deviceID, deviceType); .pushBindAppId(deviceID, Platform.isAndroid ? 10 : 20);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
AppLog.log('绑定成功'); AppLog.log('绑定成功');
} else { } else {