flutter 通知,适用安卓ios

本文记录了在Flutter应用中实现XMPP即时通讯通知的步骤,包括引入相关包和主要代码示例,适合Android和iOS平台。同时提供了作者的社区交流资源链接。
摘要由CSDN通过智能技术生成

最近在开发xmpp及时通讯,通知是必不可少的,记录下自己的成果

1 首先引入包
  cupertino_icons: ^0.1.3
  http: ^0.12.0+2
  path_provider: ^1.3.1
  shared_preferences: ^0.5.4
  rxdart: ^0.20.0
  flutter_local_notifications: ^0.8.0
2 主代码入下,自己需要修改下使用

final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
    FlutterLocalNotificationsPlugin();

// Streams are created so that app can respond to notification-related events since the plugin is initialised in the `main` function
final BehaviorSubject<ReceivedNotification> didReceiveLocalNotificationSubject =
    BehaviorSubject<ReceivedNotification>();

final BehaviorSubject<String> selectNotificationSubject =
    BehaviorSubject<String>();

class ReceivedNotification {
  final int id;
  final String title;
  final String body;
  final String payload;

  ReceivedNotification(
      {@required this.id,
      @required this.title,
      @required this.body,
      @required this.payload});
}

/// IMPORTANT: running the following code on its own won't work as there is setup required for each platform head project.
/// Please download the complete example app from the GitHub repository where all the setup has been done
Future<void> main() async {
  // needed if you intend to initialize in the `main` function
  WidgetsFlutterBinding.ensureInitialized();
  // NOTE: if you want to find out if the app was launched via notification then you could use the following call and then do something like
  // change the default route of the app
  // var notificationAppLaunchDetails =
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 我不是很清楚Flutter打包android和ios的具体流程,但是根据我从网上查询的信息,可以通过使用Flutter CLI来打包Android和iOS应用程序,并使用Flutter提供的构建工具来生成最终的应用程序文件。 ### 回答2: Flutter是一种开源的跨平台移动应用开发框架,它可以同时打包Android和iOS两个平台的应用。下面将分别介绍Flutter打包Android和iOS的步骤。 Flutter打包Android应用的步骤如下: 1. 首先,我们需要在Flutter项目的根目录下执行命令`flutter build apk`,该命令会利用Flutter的打包工具将代码编译成Android应用可执行文件。 2. 打包完成后,在项目的`build/app/outputs/apk/release`路径下会生成一个名为`app.apk`的文件,这就是我们需要的Android安装包。 3. 如果需要对该安装包进行签名,可以使用Java开发工具包(JDK)自带的`keytool`生成一个密钥库文件(keystore),然后利用Android Studio自带的`apksigner`工具对APK进行签名。 4. 最后,我们可以将签名后的APK安装包通过各种方式进行发布和安装。 Flutter打包iOS应用的步骤如下: 1. 在Flutter项目的根目录下执行命令`flutter build ios`,该命令会利用Flutter的打包工具将代码编译成iOS应用可执行文件。 2. 打包完成后,在项目的`build/ios/iphoneos`路径下会生成一个名为`Runner.app`的文件,这就是我们需要的iOS应用。 3. 接下来,我们需要在Xcode中打开`Runner.xcworkspace`文件,并配置开发者账号和相关证书。 4. 在Xcode中选择设备或模拟器,然后点击菜单栏的`Product -> Archive`选项,Xcode将会对应用进行打包。 5. 打包完成后,在`Xcode -> Window -> Organizer`界面中可以找到App Archives,我们可以选择对应的应用版本进行导出或发布。 总结来说,Flutter通过使用自身的打包工具,可以快速便捷地打包Android和iOS应用,对于开发者来说非常方便。同时,开发者还可以根据需要对打包后的应用进行签名或发布。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值