diff --git a/circle_app/ios/Runner.xcodeproj/project.pbxproj b/circle_app/ios/Runner.xcodeproj/project.pbxproj index 6cc11cb..9c1899d 100644 --- a/circle_app/ios/Runner.xcodeproj/project.pbxproj +++ b/circle_app/ios/Runner.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 78B9F60BE100248DF35D1C4A /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 8139D02F2A80CF4500E122A3 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -94,6 +95,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 8139D02F2A80CF4500E122A3 /* Runner.entitlements */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, @@ -356,6 +358,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = C97QBVP4DP; ENABLE_BITCODE = NO; @@ -503,6 +506,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = C97QBVP4DP; ENABLE_BITCODE = NO; @@ -544,6 +548,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = C97QBVP4DP; ENABLE_BITCODE = NO; diff --git a/circle_app/ios/Runner/AppDelegate.swift b/circle_app/ios/Runner/AppDelegate.swift index 70693e4..358cd1d 100644 --- a/circle_app/ios/Runner/AppDelegate.swift +++ b/circle_app/ios/Runner/AppDelegate.swift @@ -8,6 +8,10 @@ import Flutter didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) + if #available(iOS 10.0, *) { + UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate + } + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } diff --git a/circle_app/ios/Runner/Runner.entitlements b/circle_app/ios/Runner/Runner.entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/circle_app/ios/Runner/Runner.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/circle_app/lib/common/values/pushconfig.dart b/circle_app/lib/common/values/pushconfig.dart new file mode 100644 index 0000000..cd645f9 --- /dev/null +++ b/circle_app/lib/common/values/pushconfig.dart @@ -0,0 +1,87 @@ + +import 'package:tencent_chat_push_for_china/model/appInfo.dart'; +import 'package:tencent_chat_push_for_china/tencent_chat_push_for_china.dart'; + +class PushConfig{ + + //These `Business ID` can be found in the offline push section for each manufacturers, + // on the main page of console from Tencent Cloud IM. + + // Business ID for HUAWEI + static const HWPushBuzID = 0; + + // Business ID for XiaoMi + static const XMPushBuzID = 0; + + // APP Info of XiaoMi + static const String XMPushAPPID = ""; + static const String XMPushAPPKEY = ""; + + // Business ID for Meizu + static const MZPushBuzID = 0; + + // APP Info of Meizu + static const String MZPushAPPID = ""; + static const String MZPushAPPKEY = ""; + + // Business ID for Vivo + static const VIVOPushBuzID = 0; + + // Business ID for OPPO + static const OPPOPushBuzID = 0; + + // APP Info of OPPO + static const String OPPOPushAPPKEY = ""; + static const String OPPOPushAPPSECRET = ""; + static const String OPPOPushAPPID = ""; + static const String OPPOChannelID = "new_message"; + + + // Business ID for Apple APNS 正式环境39381 测试环境39382 + static const ApplePushBuzID = 39381; + + + static final PushAppInfo appInfo = PushAppInfo( + hw_buz_id: PushConfig.HWPushBuzID, + mi_app_id: PushConfig.XMPushAPPID, + mi_app_key: PushConfig.XMPushAPPKEY, + mi_buz_id: PushConfig.XMPushBuzID, + mz_app_id: PushConfig.MZPushAPPID, + mz_app_key: PushConfig.MZPushAPPKEY, + mz_buz_id: PushConfig.MZPushBuzID, + vivo_buz_id: PushConfig.VIVOPushBuzID, + oppo_app_key: PushConfig.OPPOPushAPPKEY, + oppo_app_secret: PushConfig.OPPOPushAPPSECRET, + oppo_buz_id: PushConfig.OPPOPushBuzID, + oppo_app_id: PushConfig.OPPOPushAPPID, + apple_buz_id: PushConfig.ApplePushBuzID + ); +} + + +class ChannelPush{ + static final TimUiKitPushPlugin cPush = TimUiKitPushPlugin(); + + static init(PushClickAction pushClickAction) async { + // initialize the push plugin + cPush.init( + pushClickAction: pushClickAction, + appInfo: PushConfig.appInfo, + ); + + // create new notification channel + cPush.createNotificationChannel( + channelId: "new_message", + channelName: "chat_message", + channelDescription: + "The notification for chat message from Tencent Cloud IM" + ); + + // require the permission for notification + cPush.requireNotificationPermission(); + } + + static Future getDeviceToken() async { + return cPush.getDevicePushToken(); + } +} diff --git a/circle_app/lib/main.dart b/circle_app/lib/main.dart index 188025e..868a0d4 100644 --- a/circle_app/lib/main.dart +++ b/circle_app/lib/main.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'dart:convert'; import 'package:circle_app/app/splash/binding.dart'; +import 'package:circle_app/common/values/pushconfig.dart'; import 'package:circle_app/network/api.dart'; import 'package:circle_app/network/dio_manager.dart'; import 'package:circle_app/router/app_pages.dart'; @@ -18,6 +19,9 @@ import 'package:get/get.dart'; import 'package:tencent_cloud_chat_uikit/business_logic/separate_models/tui_chat_separate_view_model.dart'; import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart'; +import 'package:tencent_chat_push_for_china/model/appInfo.dart'; + +import 'package:tencent_chat_push_for_china/tencent_chat_push_for_china.dart'; import 'app/login/login/logic.dart'; import 'app/splash/view.dart'; @@ -50,6 +54,17 @@ logoutIM() async { print(result.desc + '退出IM'); } +initPush() { + // final TimUiKitPushPlugin cPush = TimUiKitPushPlugin( + // isUseGoogleFCM: true, // 中国大陆版无此参数 + // ); + // cPush.init( + // pushClickAction: pushClickAction, // 单击通知后的事件回调,会在STEP6讲解 + // appInfo: PushConfig.appInfo, // 传入STEP1做的appInfo + // ); + +} + //跳转发消息页面 pushChatPage(String userId, String imId, String userName) async { var con = V2TimConversation( @@ -209,6 +224,8 @@ class _MyAppState extends State { if (Platform.isAndroid) { initWxApi(); } + + uploadBuzIDAndToken(); loadBgImage(); super.initState(); // getLoginStyle(); @@ -314,7 +331,7 @@ class _MyAppState extends State { splitScreenMode: true, builder: (context, child) { return GetMaterialApp( - title: 'Flutter Demo', + title: '微乐园', initialBinding: SplashBinding(), getPages: AppPages.routes, home: SplashPage(), @@ -323,4 +340,16 @@ class _MyAppState extends State { ); }); } + + //获取设备Token,获取成功后开启离线推送 + void uploadBuzIDAndToken() async { + int? businessID = await TimUiKitPushPlugin.getBuzId(PushConfig.appInfo); + String token = await ChannelPush.getDeviceToken(); + if (token != "") { + coreInstance.setOfflinePushConfig( + token: token, + businessID: businessID + ); + } + } } diff --git a/circle_app/pubspec.yaml b/circle_app/pubspec.yaml index e4203c7..b273ff4 100644 --- a/circle_app/pubspec.yaml +++ b/circle_app/pubspec.yaml @@ -93,9 +93,11 @@ dependencies: #event_bus: event_bus: ^2.0.0 #安装apk - flutter_install_app: 1.3.0 +# flutter_install_app: 1.3.0 #闪屏页 flutter_native_splash: 2.2.16 + #腾讯离线推送 + tencent_chat_push_for_china: ^2.6.2+1 dev_dependencies: flutter_test: