(1)搜索 https://pub.dartlang.org/packages/jpush_flutter ,安装插件,并且按照官方配置 /android/app/build.gradle
android: {
....
defaultConfig {
applicationId "替换成自己应用 ID"
...
ndk {
//选择要添加的对应 cpu 类型的 .so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64' // 'arm64-v8a',
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "appkey", // NOTE: JPush 上注册的包名对应的 Appkey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
]
}
}
(2)Flutter 新建页面,我放在Welcome页面
(3) 我的用是Extras 并且在客户端 通过参数 进行指定页面跳转
(4)服务端推送,C# Core版本 nuget搜索JiGuang.JPush
/// <summary>
/// 极光推送全局推送
/// </summary>
/// <param name="title">标题</param>
/// <param name="content">正文</param>
/// <param name="dic">extras字典</param>
/// <param name="indent">指定安卓页面,没用</param>
/// <param name="outmsg"></param>
/// <returns></returns>
public static bool Send(string title,string content, Dictionary<string,object> dic, Dictionary<string, object> indent,out string outmsg)
{
var client = new Jiguang.JPush.JPushClient(appKey,appSecret);
var android = new Android { Title = title, Alert = content, AlertType = 0, Extras = dic, Indent = indent };
var ios = new IOS{ Alert= title, Extras= dic };
var pushInfo = HD.DLL.Push.GetTopInfo();
if(pushInfo!=null&&pushInfo.Id>0 )
{
var ts = System.DateTime.Now.Subtract(pushInfo.Addtime);
if(ts.Hours<1)
{
outmsg = "最近的全局推送时间:"+pushInfo.Addtime+",请间隔一个小时";
return false;
}
}
var playLoad = new Jiguang.JPush.Model.PushPayload() {
Platform = "all",
//Audience = "all",
Notification = new Notification() { Alert=title, Android =android,IOS=ios},
Message = new Jiguang.JPush.Model.Message() { Content=content,Title=title,Extras= dic }
};
var response=client.SendPush(playLoad);
outmsg = response.Content;
var ret= response.StatusCode== System.Net.HttpStatusCode.OK;
//记录推送日志
pushInfo.Addtime = System.DateTime.Now;
pushInfo.Title = title;
pushInfo.Content = content;
pushInfo.UserId = 0;
pushInfo.Extras = JsonConvert.SerializeObject(dic);
pushInfo.Status = ret ? 1 : -1;
Push.Add(pushInfo);
return ret;
}