在 pubspec.yaml
中添加以下依赖:
dependencies:
getuiflut: ^0.2.38
执行以下命令下载依赖并运行项目:
flutter pub get
flutter run
或者直接通过命令行添加:
flutter pub add getuiflut
参考个推官网文档进行配置。 核心PushService、GTIntentService已经内置在flutter插件中
在项目根目录 build.gradle
文件中添加:
allprojects {
repositories {
mavenCentral()
google()
maven {
url "https://mvn.getui.com/nexus/content/repositories/releases/"
}
}
}
在 android/app/build.gradle
文件中配置:
android {
defaultConfig {
manifestPlaceholders = [
GETUI_APPID: "your appid"
]
}
}
dependencies {
//在官网查阅最新版本(https://docs.getui.com/getui/mobile/android/overview/)
implementation 'com.getui:gtsdk:3.3.12.0' // 个推 SDK
implementation 'com.getui:gtc:3.2.18.0' // 个推核心组件
}
在 main.dart
中添加以下代码以启动 SDK:
Getuiflut().startSdk(
appId: "8eLAkGIYnGAwA9fVYZU93A",
appKey: "VFX8xYxvVF6w59tsvY6XN",
appSecret: "Kv3TeED8z19QwnMLdzdI35"
);
在 Xcode 中,进入 Signing & Capabilities
,添加 Push Notifications
。
为精确统计消息送达率,可添加 Notification Service Extension
,并在 Extensions 中调用 GTExtensionSDK
的统计接口。具体参考个推 iOS 集成文档。
- 使用鸿蒙定制版 Flutter,下载地址: OpenHarmony Flutter 及 使用教程。
- ohos工程需要兼容字节码包,在项目级build-profile.json5:
"buildOption": {
"strictMode": {
"useNormalizedOHMUrl": true
}
}
在项目中配置:
"requestPermissions": [
{"name": "ohos.permission.INTERNET"},
{"name": "ohos.permission.GET_NETWORK_INFO"},
{"name": "ohos.permission.KEEP_BACKGROUND_RUNNING"},
{
"name": "ohos.permission.APP_TRACKING_CONSENT",
"reason": "$string:tracking_reason",
"usedScene": {
"abilities": ["EntryAbility"]
}
}
],
"metadata": [
{"name": "GETUI_APPID", "value": "djYjSlFVMf6p5YOy2OQUs8"},//你的appid
{"name": "ZX_CHANNELID_GT", "value": "C01-GEztJH0JLdBC"},
{"name": "client_id", "value": "109599703"},//厂商appid,开通在官网找技术支持协助
{"name": "GT_PUSH_LOG", "value": "false"} //sdk文件日志开关, 技术支持问题排查时使用
]
- 通过个推在线渠道展示的通知类消息,待通知点击打开目的页面后,由客户必须调用PushManager.setClickWant(want)完善报表和完成后续业务,以免影响消息业务使用(重要)
- 通知点击打开应用页面(目的页面由下发通知时决定)
- 通知点击打开浏览器
参考demo代码: EntryAbility.ets
参考: 官网文档
导入插件:
import 'package:getuiflut/getuiflut.dart';
Getuiflut().initGetuiSdk;
setBadge(badge);
bindAlias(alias, sn);
unbindAlias(alias, sn);
- sn: 绑定序列码,不为nil
setTag(tags,sn);
queryTag(sn)
- sn: 绑定序列码,不为nil
turnOnPush();
turnOffPush();
getClientId();
setSilentTime(beginHour,duration)
- 开始时间,beginHour >= 0 && beginHour < 24,单位 h
- duration:持续时间,duration > 0 && duration <= 23,持续时间为 0 则取消静默,单位 h
sendFeedbackMessage( taskId, messageId, actionId)
- actionId:自定义的actionId,取值范围是 90001-90999
设置事件监听:
Getuiflut().addEventHandler(
onReceiveClientId: (String message) async {
print("flutter onReceiveClientId: $message");
}, onReceiveOnlineState: (String online) async {
print("flutter onReceiveOnlineState: $online");
},onReceivePayload: (Map<String, dynamic> message) async {
print("flutter onReceivePayload: $message");
},onSetTagResult: (Map<String, dynamic> message) async {
print("flutter onSetTagResult: $message");
}, onAliasResult: (Map<String, dynamic> message) async {
print("flutter onAliasResult: $message");
}, onQueryTagResult: (Map<String, dynamic> message) async {
print("flutter onQueryTagResult: $message");
},onRegisterDeviceToken: (String message) async {
print("flutter onRegisterDeviceToken: $message");
},
//Android 、ohos 特有
onNotificationMessageArrived: (Map<String, dynamic> msg) async {
print("flutter onNotificationMessageArrived: $msg");
}, onNotificationMessageClicked: (Map<String, dynamic> msg) async {
print("flutter onNotificationMessageClicked: $msg");
},
//以下IOS特有
onTransmitUserMessageReceive: (Map<String, dynamic> msg) async {
print("flutter onTransmitUserMessageReceive:$msg");
},onReceiveNotificationResponse: (Map<String, dynamic> message) async {
print("flutter onReceiveNotificationResponse: $message");
}, onAppLinkPayload: (String message) async {
print("flutter onAppLinkPayload: $message");
}, onPushModeResult: (Map<String, dynamic> message) async {
print("flutter onPushModeResult: $message");
}, onWillPresentNotification: (Map<String, dynamic> message) async {
print("flutter onWillPresentNotification: $message");
}, onOpenSettingsForNotification: (Map<String, dynamic> message) async {
print("flutter onOpenSettingsForNotification: $message");
}, onGrantAuthorization: (String granted) async {
print("flutter onGrantAuthorization: $granted");
}, onLiveActivityResult: (Map<String, dynamic> message) async {
print("flutter onLiveActivityResult: $message");
}, onRegisterPushToStartTokenResult: (Map<String, dynamic> message) async {
print("flutter onRegisterPushToStartTokenResult: $message");
});
startSdk(appId, appKey, appSecret);
startSdkSimple(appId, appKey, appSecret);
registerRemoteNotification(appId, appKey, appSecret);
getLaunchOptions();
getLaunchNotification();
setBadge(badge);
resetBadge();
setLocalBadge(badge);
runBackgroundEnable(enable);
registerActivityToken(aid, token, sn);
registerPushToStartToken(attribute, token, sn);
在 AppDelegate.m
中重写以下方法以确保 SDK 正常工作:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// 保持空实现
}
版本兼容性:
- GTSDK ≤ 2.4.6.0:使用插件版本 ≤ 0.2.5
- GTSDK > 2.4.6.0:使用最新插件版本
**说明**:如需更多细节,可参考[个推官方文档](https://docs.getui.com),联系技术支持。