Flutter iOS极光推送实现过程

在Flutter项目中集成极光推送时,iOS平台始终无法收到推送消息。按照官方文档配置了AppKey、证书上传到极光后台,并添加了NotificationService扩展。但测试发现:

  1. 应用在前台时能获取到推送内容,但后台/杀死状态无通知栏展示
  2. 通过JPush API发送的推送,极光后台显示送达,iOS设备实际未收到
  3. 已确认Capabilities开启Push Notifications和Background Modes
  4. 证书环境(Development/Production)与JPush配置一致
    请问可能遗漏哪些关键步骤?是否需要特殊处理Flutter与原生iOS的桥接部分?

更多关于Flutter iOS极光推送实现过程的实战教程也可以访问 https://www.itying.com/category-92-b0.html

3 回复

实现Flutter iOS极光推送的过程如下:

  1. 配置极光推送

    • 注册极光推送服务并获取AppKey
    • 在极光官网下载iOS平台的SDK和证书。
  2. 配置Xcode项目

    • 导入极光推送SDK到项目中。
    • 配置Apple Push Notification服务的APNs证书。
    • 修改Info.plist添加权限描述,如通知权限NSUserNotificationUsageDescription
  3. 集成Flutter插件

    • 使用flutter_jpush插件管理推送功能。
    • 初始化插件,在AppDelegate.m中调用[JPUSHService setupWithOption:launchOptions]
  4. 请求用户授权

    • 调用JPush.requestPermission()请求通知权限。
  5. 处理推送接收

    • 实现didReceiveRemoteNotification方法接收推送消息。
    • 在Flutter端监听消息事件,通过MethodChannel传递数据。
  6. 测试推送

    • 使用极光推送后台发送测试消息。
    • 确保设备在线接收推送。
  7. 优化与调试

    • 处理推送角标、自定义通知样式。
    • 使用极光提供的调试工具排查问题。

记得每次更新应用时重新生成签名文件,并确保配置正确。

更多关于Flutter iOS极光推送实现过程的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


首先在极光官网注册账号并创建应用获取AppKey。在Flutter项目中添加flutter_local_notificationsjpush_flutter插件。

初始化:在AppDelegate的didFinishLaunchingWithOptions中调用JPUSHService.setup完成极光推送配置,并设置tag、alias等信息。

在iOS端处理推送证书:在苹果开发者后台生成推送服务SSL证书,下载后导入到项目中并上传至极光平台。

接收推送:重写application:didReceiveRemoteNotification:方法,将接收到的通知传递给极光SDK处理。

后台模式下接收:在Info.plist中添加UIBackgroundModes字段并开启推送功能,确保应用在后台也能接收消息。

测试与上线:使用极光提供的调试工具发送测试推送,确认功能正常后提交应用至App Store。

注意,不同版本的iOS系统对推送权限请求弹窗有不同规则,需根据实际情况调整代码逻辑。

以下是在Flutter中实现iOS极光推送(JPush)的步骤:

  1. 添加依赖 在pubspec.yaml中添加:
dependencies:
  jpush_flutter: ^2.0.0
  1. iOS配置
  • 在Xcode中添加Push Notification capability
  • 在AppDelegate.swift中添加:
import Flutter
import UIKit
import jpush_flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    JPUSHService.setup(withOption: launchOptions, appKey: "你的AppKey", channel: "AppStore", apsForProduction: false)
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
  1. Flutter代码初始化
import 'package:jpush_flutter/jpush_flutter.dart';

final JPush jpush = JPush();

void initPlatformState() async {
  // 初始化
  jpush.setup(
    appKey: "你的AppKey",
    channel: "developer-default",
    production: false,
    debug: true,
  );

  // 监听通知点击
  jpush.addEventHandler(
    onReceiveNotification: (Map<String, dynamic> message) async {},
    onOpenNotification: (Map<String, dynamic> message) async {},
    onReceiveMessage: (Map<String, dynamic> message) async {},
  );
  
  // 获取RegistrationID
  String? registrationID = await jpush.getRegistrationID();
}
  1. 设置别名(可选)
jpush.setAlias("user123").then((map) {
  print("设置别名成功: $map");
});
  1. 注意事项
  • 确保在苹果开发者中心配置了推送证书
  • 首次启动需要用户授权推送权限
  • 测试时使用Development环境证书,上线后切换Production

需要先在极光官网创建应用获取AppKey,并配置iOS推送证书。

回到顶部