• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

flutter对接极光推送

武飞扬头像
曲黎雪
帮助1

  1. 注册极光账号,创建应用
    安卓需要填写应用的包名
    iOS需要填写Bundle ID
    推荐使用Token Authentication配置
    1.获取APNs Auth Key
    苹果版IOS云消息推送配置教程,P8密钥制作APNs Auth Key获取Key ID - 一门APP (yimenapp.com)学新通https://www.yimenapp.com/info/ping-guo-ban-IOS-yun-xiao-xi-tui-song-pei-zhi-jiao-cheng-P8-mi-yao-zhi-zuo-APNs-Auth-Key-huo-qu-Key-ID-589.html
    请跳转上述教程
    2.获取Team ID
    苹果版IOS云消息推送配置教程,P8密钥制作APNs Auth Key获取Key ID - 一门APP (yimenapp.com)学新通https://www.yimenapp.com/info/ping-guo-ban-IOS-yun-xiao-xi-tui-song-pei-zhi-jiao-cheng-P8-mi-yao-zhi-zuo-APNs-Auth-Key-huo-qu-Key-ID-589.html
    请跳转上述教程

     
  2. 安卓配置
    去android->app->build.gradle中进行下列配置
     
    1.  
      defaultConfig {
    2.  
      applicationId "包名"
    3.  
      minSdkVersion 21
    4.  
      targetSdkVersion 30
    5.  
      versionCode flutterVersionCode.toInteger()
    6.  
      versionName flutterVersionName
    7.  
      multiDexEnabled true
    8.  
       
    9.  
      ndk {
    10.  
      //选择要添加的对应 cpu 类型的 .so 库。
    11.  
      abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a'
    12.  
      }
    13.  
       
    14.  
      manifestPlaceholders = [
    15.  
      JPUSH_PKGNAME : "包名",
    16.  
      JPUSH_APPKEY : "Appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
    17.  
      JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
    18.  
      ]
    19.  
      }
    学新通

     
  3. iOS配置

    看下图中,XCode中选中即可
    学新通


    出现下图即可
    学新通


     
  4. 初始化推送插件

    在pubspec.yaml中的dependencies中添加
    1.  
      #极光推送
    2.  
      jpush_flutter: 2.1.4
    然后封装一个工具类
    1.  
      class PushUtil {
    2.  
      static JPush? pushUtil;
    3.  
       
    4.  
      static initPush() async {
    5.  
      if (pushUtil == null) {
    6.  
      pushUtil = JPush();
    7.  
      }
    8.  
       
    9.  
      try {
    10.  
      pushUtil!.addEventHandler(
    11.  
      onReceiveNotification: (Map<String, dynamic> message) async {
    12.  
      debugPrint("flutter onReceiveNotification: $message");
    13.  
      },
    14.  
       
    15.  
      ///点击的回调事件
    16.  
      onOpenNotification: (Map<String, dynamic> message) async {
    17.  
      debugPrint("flutter onOpenNotification: $message");
    18.  
      }, onReceiveMessage: (Map<String, dynamic> message) async {
    19.  
      debugPrint("flutter onReceiveMessage: $message");
    20.  
      }, onReceiveNotificationAuthorization:
    21.  
      (Map<String, dynamic> message) async {
    22.  
      debugPrint("flutter onReceiveNotificationAuthorization: $message");
    23.  
      });
    24.  
      } on PlatformException {
    25.  
      // platformVersion = 'Failed to get platform version.';
    26.  
      }
    27.  
       
    28.  
      pushUtil!.setup(
    29.  
      appKey: Platform.isIOS ? 'iOS AppKey' : "Android AppKey", //你自己应用的 AppKey
    30.  
      channel: "theChannel",
    31.  
      production: false,
    32.  
      debug: true,
    33.  
      );
    34.  
       
    35.  
      ///声音,震动等设置
    36.  
      pushUtil!.applyPushAuthority(
    37.  
      new NotificationSettingsIOS(sound: true, alert: true, badge: false));
    38.  
       
    39.  
      ///给后台的registration id
    40.  
      pushUtil!.getRegistrationID().then((rid) {
    41.  
      print("flutter get registration id : $rid");
    42.  
      });
    43.  
      }
    44.  
      }
    学新通


    然后在runApp(MyApp)的MyApp中初始化
     

    1.  
      ///初始化极光推送
    2.  
      PushUtil.initPush();
    获取registrationID
    1.  
      ///获取极光推送注册id
    2.  
      String registrationID = await PushUtil.pushUtil!.getRegistrationID();


     

  5. 遇到的一些坑
    iOS发布到App Store上以后,安卓也上正式
    安卓的推送可以正常收到,iOS的正式环境收不到
    后面经过和客服沟通,发现是后台发起推送时,
    配置的问题
    apns_production true正式 false测试

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgakkgj
系列文章
更多 icon
同类精品
更多 icon
继续加载