Flutter应用内消息插件notificare_in_app_messaging的使用
Flutter应用内消息插件notificare_in_app_messaging的使用
Notificare Flutter SDK
Notificare Flutter SDK 可以快速且轻松地与许多 Notificare API 服务进行通信,并使您可以无缝集成各种功能,从推送通知到上下文存储。
目录
特性
推送通知: 接收推送通知并自动跟踪其参与度。
推送通知UI: 使用原生屏幕和元素来显示您的推送通知并处理其操作,无需任何努力。
应用内消息: 自动向用户展示相关的应用内内容,无需任何努力。
收件箱: 带有内置消息收件箱的应用程序由于其可以打开多次的消息性质而享受更高的转化率。SDK为您提供构建收件箱UI所需的所有工具。
地理定位: 将用户的位置转化为相关信息,自动化基于位置行为的用户分段并创建真正的上下文通知。
忠诚度: 发挥数字卡的力量,这些卡存在于您的应用之外,始终在客户口袋里。
资产: 为您的应用程序添加强大的上下文营销功能。在正确的时间或地点向正确的用户展示合适的内容。最大化您已经创建的内容,而不会增加开发成本。
可扫描内容: 通过扫描NFC标签或QR码解锁新内容,这些内容可以无缝集成到您的移动应用程序中。
安装
需求
- Android 6 (API 级别 23) 及以上
- iOS 11 及以上
配置
将 Flutter 包添加到您的 pubspec.yaml
文件并遵循开始使用指南。
dependencies:
# 必须的
notificare: ^4.0.0
# 可选模块
notificare_assets: ^4.0.0
notificare_geo: ^4.0.0
notificare_inbox: ^4.0.0
notificare_loyalty: ^4.0.0
notificare_push: ^4.0.0
notificare_push_ui: ^4.0.0
notificare_scannables: ^4.0.0
开始使用
集成
示例
- 示例项目 以简化的方式展示了其他集成,以便快速了解如何实现给定的功能。
示例代码
以下是一个简单的示例代码,展示如何使用 notificare_in_app_messaging
插件:
import 'package:flutter/material.dart';
import 'package:notificare/notificare.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
[@override](/user/override)
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// 初始化插件
Future<void> initializePlugin() async {
await Notificare.initialize(
appId: "YOUR_APP_ID",
appKey: "YOUR_APP_KEY",
);
}
[@override](/user/override)
void initState() {
super.initState();
// 初始化时调用
initializePlugin();
}
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('In-app Messaging Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () async {
// 获取应用内消息
final messages = await Notificare.inAppMessaging().getMessages();
// 打印获取到的消息
print("Received messages: $messages");
},
child: Text('Fetch In-app Messages'),
),
),
),
);
}
}
更多关于Flutter应用内消息插件notificare_in_app_messaging的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter应用内消息插件notificare_in_app_messaging的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
notificare_in_app_messaging
是一个用于在 Flutter 应用中显示应用内消息的插件。它是 Notificare 平台的一部分,Notificare 是一个为移动应用提供丰富的推送通知和应用内消息的解决方案。
以下是如何在 Flutter 应用中使用 notificare_in_app_messaging
插件的基本步骤:
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 notificare_in_app_messaging
插件的依赖:
dependencies:
flutter:
sdk: flutter
notificare_in_app_messaging: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来获取依赖。
2. 初始化 Notificare
在使用 notificare_in_app_messaging
之前,你需要在应用启动时初始化 Notificare。通常,你可以在 main.dart
文件中进行初始化:
import 'package:flutter/material.dart';
import 'package:notificare_flutter/notificare_flutter.dart';
import 'package:notificare_in_app_messaging/notificare_in_app_messaging.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 初始化 Notificare
await Notificare.initialize(
'your-app-key', // 替换为你的应用 key
'your-app-secret', // 替换为你的应用 secret
);
// 启动 Notificare
await Notificare.launch();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Notificare In-App Messaging Demo',
home: InAppMessagingDemo(),
);
}
}
3. 处理应用内消息
你可以在应用的任何地方使用 NotificareInAppMessaging
来处理应用内消息。以下是一个简单的示例,展示如何显示应用内消息:
import 'package:flutter/material.dart';
import 'package:notificare_in_app_messaging/notificare_in_app_messaging.dart';
class InAppMessagingDemo extends StatefulWidget {
[@override](/user/override)
_InAppMessagingDemoState createState() => _InAppMessagingDemoState();
}
class _InAppMessagingDemoState extends State<InAppMessagingDemo> {
[@override](/user/override)
void initState() {
super.initState();
_initInAppMessaging();
}
Future<void> _initInAppMessaging() async {
// 监听应用内消息事件
NotificareInAppMessaging.onMessagePresented.listen((message) {
print('In-App Message Presented: ${message.messageId}');
});
NotificareInAppMessaging.onMessageFailedToPresent.listen((message) {
print('In-App Message Failed to Present: ${message.messageId}');
});
NotificareInAppMessaging.onMessageFinishedPresenting.listen((message) {
print('In-App Message Finished Presenting: ${message.messageId}');
});
NotificareInAppMessaging.onMessageClicked.listen((message) {
print('In-App Message Clicked: ${message.messageId}');
});
// 检查是否有待显示的应用内消息
await NotificareInAppMessaging.checkMessages();
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('In-App Messaging Demo'),
),
body: Center(
child: Text('Check the console for In-App Messaging events.'),
),
);
}
}