flutter_umeng_analytics_push

Last updated:

0 purchases

flutter_umeng_analytics_push Image
flutter_umeng_analytics_push Images
Add to Cart

Description:

flutter umeng analytics push

友盟分析推送Flutter插件(flutter_umeng_analytics_push) #
用法 #
Flutter导入 #
1、自动集成
dependencies:
flutter_umeng_analytics_push: ^1.0.2
copied to clipboard
2、 本地导入(二选一,下载代码或者git clone)
dependencies:
flutter_umeng_analytics_push:
git:
url: https://github.com/youyiio/flutter_umeng_analytics_push.git
copied to clipboard
Android设置(以Kotlin示例) #
创建自定义FlutterApplication类作为启动类,如果不需要push功能则uemng_push_id设置为空,如果不需要自定义Push点击,则设置最后一个参数为false
package com.demo.umeng.app

import io.flutter.app.FlutterApplication
import com.beyongx.flutter_umeng_analytics_push.UmengAnalyticsPushFlutterAndroid

class MyFlutterApplication: FlutterApplication() {
override fun onCreate() {
super.onCreate();
UmengAnalyticsPushFlutterAndroid.androidInit(this, "umeng_app_key", "default",
false, "umeng_message_secret")
}
}
copied to clipboard
修改MainActivity,增加Umeng的设置
package com.demo.umeng.app

import android.os.Handler
import android.os.Looper
import android.content.Intent
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
import com.beyongx.flutter_umeng_analytics_push.UmengAnalyticsPushFlutterAndroid
import com.beyongx.flutter_umeng_analytics_push.UmengAnalyticsPushPlugin

class MainActivity: FlutterActivity() {
var handler: Handler = Handler(Looper.myLooper())

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}

override fun onNewIntent(intent: Intent) {
// Actively update and save the intent every time you go back to the front desk, and then you can get the latest intent
setIntent(intent);
super.onNewIntent(intent);
}

override fun onResume() {
super.onResume()
UmengAnalyticsPushFlutterAndroid.androidOnResume(this)
if (getIntent().getExtras() != null) {
var message = getIntent().getExtras().getString("message")
if (message != null && message != "") {
// To start the interface, wait for the engine to load, and send it to the interface with a delay of 5 seconds
handler.postDelayed(object : Runnable {
override fun run() {
UmengAnalyticsPushPlugin.eventSink.success(message)
}
}, 5000)
}
}
}

override fun onPause() {
super.onPause()
UmengAnalyticsPushFlutterAndroid.androidOnPause(this)
}
}
copied to clipboard
修改AndroidManifest.xml文件
<application
android:name="com.demo.umeng.app.MyFlutterApplication">
</application>
copied to clipboard
加入厂商通道, 详见官方文档 umeng:push:vendor
修改MyFlutterApplication
package com.demo.umeng.app

import io.flutter.app.FlutterApplication
import com.beyongx.flutter_umeng_analytics_push.UmengAnalyticsPushFlutterAndroid

class MyFlutterApplication: FlutterApplication() {
override fun onCreate() {
super.onCreate();

UmengAnalyticsPushFlutterAndroid.androidInit(this, "uemng_app_key", "default",
false, "uemng_message_secret", false)
// Register Xiaomi Push (optional)
UmengAnalyticsPushFlutterAndroid.registerXiaomi(this, "xiaomi_app_id", "xiaomi_app_key")
// Register Huawei Push (optional, need add other infomation in AndroidManifest.xml)
UmengAnalyticsPushFlutterAndroid.registerHuawei(this)
// Register Oppo Push (optional)
UmengAnalyticsPushFlutterAndroid.registerOppo(this, "oppo_app_key", "oppo_app_secret")
// Register Vivo Push (optional, need add other infomation in AndroidManifest.xml)
UmengAnalyticsPushFlutterAndroid.registerVivo(this)
// Register Meizu Push (optional)
UmengAnalyticsPushFlutterAndroid.registerMeizu(this, "meizu_app_id", "meizu_app_key")
}
}
copied to clipboard
配置手机厂商的push key
注意在主项目中即可,修改AndroidManifest.xml, 填写appId和key
<application
android:name="com.demo.umeng.app.MyFlutterApplication">
.....

<!-- Vivo push channel start (optional) -->
<meta-data
android:name="com.vivo.push.api_key"
android:value="vivo_api_key" />
<meta-data
android:name="com.vivo.push.app_id"
android:value="vivo_app_id" />
<!-- Vivo push channel end-->

<!-- Huawei push channel start (optional) -->
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="appid=${huawei_app_id}" />
<!-- Huawei push channel end-->
</application>
copied to clipboard
设备离线下,认可接受离线消息
友盟后台手动测试时;

设定厂商通道
填写 ”打开指定页面“: com.beyongx.flutter_umeng_analytics_push.OfflineNotifyClickActivity

调用友盟推送接口时,使用下面的参数发送
"mipush": true
"mi_activity": "com.beyongx.flutter_umeng_analytics_push.OfflineNotifyClickActivity"
copied to clipboard
IOS设置(以Swift示例) #
修改AppDelegate.swift文件,如果不需要Push功能则pushEnabled设置为false
import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
UmengAnalyticsPushFlutterIos.iosInit(launchOptions, appkey:"uemng_app_key", channel:"appstore", logEnabled:false, pushEnabled:true);
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

// 如果需要处理Push点击,用下面代码
@available(iOS 10.0, *)
override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
UmengAnalyticsPushFlutterIos.handleMessagePush(userInfo)
completionHandler()
}
}
copied to clipboard
修改Runner-Bridging-Header.h文件
#import "GeneratedPluginRegistrant.h"
#import <UMCommon/UMCommon.h>
#import <UMCommon/MobClick.h>
#import <UMPush/UMessage.h>
#import <UserNotifications/UserNotifications.h>
#import <flutter_umeng_analytics_push/UmengAnalyticsPushIos.h>
copied to clipboard
Flutter中使用 #
点击Push响应
import 'package:flutter_umeng_analytics_push/flutter_umeng_analytics_push.dart';
import 'package:flutter_umeng_analytics_push/message_model.dart';

FlutterUmengAnalyticsPush.addPushMessageCallback((MessageModel message) {
print("UmengAnalyticsPush Message ======> $message");
});
copied to clipboard
操作Alias
import 'package:flutter_umeng_analytics_push/flutter_umeng_analytics_push.dart';

FlutterUmengAnalyticsPush.addAlias('1001', 'jobcode');
FlutterUmengAnalyticsPush.setAlias('1002', 'jobcode');
FlutterUmengAnalyticsPush.deleteAlias('1002', 'jobcode');
copied to clipboard
操作Tags
import 'package:flutter_umeng_analytics_push/flutter_umeng_analytics_push.dart';

FlutterUmengAnalyticsPush.addTags('manager');
FlutterUmengAnalyticsPush.deleteTags('manager');
copied to clipboard
页面埋点操作
import 'package:flutter_umeng_analytics_push/flutter_umeng_analytics_push.dart';

FlutterUmengAnalyticsPush.pageStart('memberPage');
FlutterUmengAnalyticsPush.pageEnd('memberPage');
copied to clipboard
自定义事件
import 'package:flutter_umeng_analytics_push/flutter_umeng_analytics_push.dart';

FlutterUmengAnalyticsPush.event('customEvent', '1000');
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.