(1)搜索 https://pub.dartlang.org/packages/jpush_flutter ,安裝插件,而且按照官方配置 /android/app/build.gradleandroid
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頁面ios
(3) 個人用是Extras 而且在客戶端 經過參數 進行指定頁面跳轉json
(4)服務端推送,C# Core版本 nuget搜索JiGuang.JPushapp
/// <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;async
//記錄推送日誌
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;
}ide