Commit 67ac21a7 by tanghuan

延迟初始化推送SDK

1 parent 5e48d4f1
...@@ -91,6 +91,9 @@ flutter { ...@@ -91,6 +91,9 @@ flutter {
} }
dependencies { dependencies {
// 添加 AppCompat 支持库(PrivacyActivity需要)
implementation("androidx.appcompat:appcompat:1.6.1")
// implementation("com.tencent.timpush:timpush:8.7.7201") // implementation("com.tencent.timpush:timpush:8.7.7201")
// implementation("com.tencent.liteav.tuikit:tuicore:8.7.7201") // implementation("com.tencent.liteav.tuikit:tuicore:8.7.7201")
// 版本号 "VERSION" 请前往 更新日志 中获取配置。 // 版本号 "VERSION" 请前往 更新日志 中获取配置。
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<application <application
android:label="班小二" android:label="班小二"
android:name="${applicationName}" android:name="cn.banxe.bxe.MyApplication"
android:icon="@mipmap/launcher_icon" android:icon="@mipmap/launcher_icon"
android:networkSecurityConfig="@xml/network_security_config"> android:networkSecurityConfig="@xml/network_security_config">
......
package cn.banxe.bxe; package cn.banxe.bxe;
import android.content.Context;
import android.content.SharedPreferences;
import com.tencent.chat.flutter.push.tencent_cloud_chat_push.application.TencentCloudChatPushApplication; import com.tencent.chat.flutter.push.tencent_cloud_chat_push.application.TencentCloudChatPushApplication;
public class MyApplication extends TencentCloudChatPushApplication { public class MyApplication extends TencentCloudChatPushApplication {
private static final String PREFS_NAME = "privacy_prefs";
private static final String KEY_AGREED = "privacy_agreed";
private static MyApplication instance;
@Override @Override
public void onCreate() { public void onCreate() {
instance = this;
// 只有在用户已同意隐私政策时才执行初始化
if (isPrivacyAgreed()) {
super.onCreate();
}
}
private boolean isPrivacyAgreed() {
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
return prefs.getBoolean(KEY_AGREED, false);
}
/**
* 用户同意隐私政策后调用,执行延迟初始化
*/
public static void onPrivacyAgreed() {
if (instance != null && !instance.isPrivacyAgreed()) {
// 先保存同意状态
instance.savePrivacyAgreed();
// 再执行初始化
instance.initSDKs();
}
}
private void savePrivacyAgreed() {
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().putBoolean(KEY_AGREED, true).apply();
}
private void initSDKs() {
// 执行父类的初始化逻辑v
super.onCreate(); super.onCreate();
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -155,9 +155,9 @@ public class PrivacyActivity extends Activity { ...@@ -155,9 +155,9 @@ public class PrivacyActivity extends Activity {
} }
private SpannableString createClickableContent() { private SpannableString createClickableContent() {
String text = "请您仔细阅读《用户协议》和《隐私政策》,\n充分理解协议内容。\n\n" + String text = "请您仔细阅读《用户协议》和《隐私政策》,充分理解协议内容。\n\n" +
"我们将严格遵守相关法律法规,保护您的个人信息安全。\n\n" + "我们将严格遵守相关法律法规,保护您的个人信息安全。\n\n" +
"点击\"同意\"即表示您已阅读并同意相关协议。"; "点击“同意”即表示您已阅读并同意相关协议。";
SpannableString spannableString = new SpannableString(text); SpannableString spannableString = new SpannableString(text);
...@@ -202,7 +202,8 @@ public class PrivacyActivity extends Activity { ...@@ -202,7 +202,8 @@ public class PrivacyActivity extends Activity {
} }
private void onAgreeClicked() { private void onAgreeClicked() {
savePrivacyAgreed(); // 触发 Application 中的延迟初始化
MyApplication.onPrivacyAgreed();
startMainActivity(); startMainActivity();
} }
......
import 'dart:io';
import 'package:appframe/config/constant.dart'; import 'package:appframe/config/constant.dart';
import 'package:appframe/config/locator.dart'; import 'package:appframe/config/locator.dart';
import 'package:appframe/config/routes.dart'; import 'package:appframe/config/routes.dart';
...@@ -86,7 +88,9 @@ class LoginMainCubit extends Cubit<LoginMainState> { ...@@ -86,7 +88,9 @@ class LoginMainCubit extends Cubit<LoginMainState> {
_userAuthRepository = getIt.get<UserAuthRepository>(); _userAuthRepository = getIt.get<UserAuthRepository>();
// 检查是否首次打开登录页面,显示个人信息收集提示 // 检查是否首次打开登录页面,显示个人信息收集提示
_checkFirstTimePrivacy(); if(Platform.isIOS) {
_checkFirstTimePrivacy();
}
} }
// 检查是否首次打开,显示个人信息收集提示 // 检查是否首次打开,显示个人信息收集提示
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!