From db9c4caba6bca64dcd220a73badb811181643539 Mon Sep 17 00:00:00 2001 From: "xj.deng" Date: Tue, 18 Jun 2019 11:09:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=EF=BC=8Cios/android,test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 17 ++++++ ios/Runner.xcodeproj/project.pbxproj | 13 +++- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++ ios/Runner/AppDelegate.m | 3 + ios/Runner/Info.plist | 2 + ios/Runner/Runner.entitlements | 8 +++ lib/main.dart | 61 +++++++++++++++++++ pubspec.lock | 9 ++- pubspec.yaml | 1 + 9 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 ios/Runner/Runner.entitlements diff --git a/android/app/build.gradle b/android/app/build.gradle index 03806468..847acc04 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -51,8 +51,23 @@ android { versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + manifestPlaceholders = [ + JPUSH_PKGNAME : "com.alibaba.fluttergo", + JPUSH_APPKEY : "62eb07d227d1f11dd7fa6239", //JPush上注册的包名对应的appkey. + JPUSH_CHANNEL : "developer-default", + ] + +// ndk { +// //选择要添加的对应cpu类型的.so库。 +// abiFilters 'armeabi', 'armeabi-v7a','x86', 'x86_64', 'mips'//, 'arm64-v8a' +// // 还可以添加 'x86', 'x86_64', 'mips', 'mips64' +// } + } + + signingConfigs { release { keyAlias keystoreProperties['keyAlias'] @@ -86,6 +101,8 @@ dependencies { ///implementation 'com.google.firebase:firebase-perf:16.2.3' // 登陆 ////implementation 'com.google.firebase:firebase-auth:16.0.3' + + } //firebase apply plugin: 'com.google.gms.google-services' diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 8eb0a6fe..7e2b49ae 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -72,6 +72,7 @@ 0828E494220692B500A59437 /* iPhone XR Landscape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "iPhone XR Landscape.png"; sourceTree = ""; }; 0828E4A42206936100A59437 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 084A20872202E4FD00428FF5 /* flutter go.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "flutter go.png"; sourceTree = ""; }; + 10D9E78922B7651B003C2C98 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = ""; }; 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 = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; @@ -184,6 +185,7 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 10D9E78922B7651B003C2C98 /* Runner.entitlements */, 94722E5B22511D3600F63900 /* GoogleService-Info.plist */, 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, @@ -246,6 +248,11 @@ CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 4WLT68XRNA; ProvisioningStyle = Manual; + SystemCapabilities = { + com.apple.Push = { + enabled = 1; + }; + }; }; }; }; @@ -530,7 +537,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = Launch2; - CODE_SIGN_IDENTITY = "iPhone Distribution"; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; + CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; DEVELOPMENT_TEAM = 4WLT68XRNA; @@ -547,7 +555,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.alibaba.fluttergo; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = FlutterGO_alibaba_distribution_app_store; + PROVISIONING_PROFILE_SPECIFIER = "FlutterGO-alibaba-develop"; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -558,6 +566,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = Launch2; + CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_IDENTITY = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; diff --git a/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/Runner/AppDelegate.m b/ios/Runner/AppDelegate.m index 7474c39b..b8535aec 100644 --- a/ios/Runner/AppDelegate.m +++ b/ios/Runner/AppDelegate.m @@ -1,5 +1,6 @@ #include "AppDelegate.h" #include "GeneratedPluginRegistrant.h" +#include "FlutterJPushPlugin.h" @import Firebase;//增加 firebase 支持 @@ -10,6 +11,8 @@ [FIRApp configure];//增加 firebase 支持 + [self startupJPush:launchOptions appKey:@"62eb07d227d1f11dd7fa6239" channel:@"jpush" isProduction:FALSE]; + [GeneratedPluginRegistrant registerWithRegistry:self]; // Override point for customization after application launch. [NSThread sleepForTimeInterval:2]; diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index d94b59b8..c6bb52b8 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -22,6 +22,8 @@ ???? CFBundleVersion $(FLUTTER_BUILD_NUMBER) + LSApplicationCategoryType + LSRequiresIPhoneOS NSCameraUsageDescription diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements new file mode 100644 index 00000000..903def2a --- /dev/null +++ b/ios/Runner/Runner.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/lib/main.dart b/lib/main.dart index 1ed73202..851465b6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,7 @@ import 'package:flutter_go/utils/analytics.dart' as Analytics; import 'package:flutter_go/views/login_page/login_page.dart'; import 'package:flutter_go/utils/data_utils.dart'; import 'package:flutter_go/model/user_info.dart'; +import 'package:flutter_jpush/flutter_jpush.dart'; //import 'views/welcome_page/index.dart'; @@ -36,10 +37,61 @@ class _MyAppState extends State { bool _hasLogin = false; bool _isLoading = true; UserInformation _userInfo; + bool isConnected = false; + String registrationId; + List notificationList = []; @override void initState() { super.initState(); + _startupJpush(); + + FlutterJPush.addConnectionChangeListener((bool connected) { + setState(() { + /// 是否连接,连接了才可以推送 + print("连接状态改变:$connected"); + this.isConnected = connected; + if (connected) { + //在启动的时候会去连接自己的服务器,连接并注册成功之后会返回一个唯一的设备号 + FlutterJPush.getRegistrationID().then((String regId) { + print("主动获取设备号:$regId"); + setState(() { + this.registrationId = regId; + }); + }); + } + }); + }); + + FlutterJPush + .addReceiveNotificationListener((JPushNotification notification) { + setState(() { + /// 收到推送 + print("收到推送提醒: $notification"); + notificationList.add(notification); + }); + }); + + FlutterJPush + .addReceiveOpenNotificationListener((JPushNotification notification) { + setState(() { + print("打开了推送提醒: $notification"); + + /// 打开了推送提醒 + notificationList.add(notification); + }); + }); + + FlutterJPush.addReceiveCustomMsgListener((JPushMessage msg) { + setState(() { + print("收到推送消息提醒: $msg"); + + /// 打开了推送提醒 + notificationList.add(msg); + }); + }); + + DataUtils.checkLogin().then((hasLogin) { if (hasLogin.runtimeType == UserInformation) { setState(() { @@ -105,6 +157,15 @@ class _MyAppState extends State { } } + + +void _startupJpush() async { + print("初始化jpush"); + await FlutterJPush.startup(); + print("初始化jpush成功"); +} + + void main() async { final provider = new Provider(); await provider.init(true); diff --git a/pubspec.lock b/pubspec.lock index b1084af3..b4a41158 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -125,6 +125,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.7" + flutter_jpush: + dependency: "direct main" + description: + name: flutter_jpush + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4" flutter_markdown: dependency: "direct main" description: @@ -213,7 +220,7 @@ packages: name: open_file url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" package_info: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 921f5e25..d35086cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: permission_handler: ^3.0.0 open_file: ^2.0.1+2 package_info: ^0.4.0+3 + flutter_jpush: ^0.0.4 dev_dependencies: flutter_test: