{"id":994,"date":"2024-05-14T20:39:59","date_gmt":"2024-05-14T12:39:59","guid":{"rendered":"https:\/\/gjweb.top\/?p=994"},"modified":"2024-05-14T20:40:02","modified_gmt":"2024-05-14T12:40:02","slug":"flutter-%e6%9e%81%e5%85%89%e6%8e%a8%e9%80%81%e5%89%8d%e5%90%8e%e7%ab%af%e8%90%bd%e5%9c%b0%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=994","title":{"rendered":"flutter \u6781\u5149\u63a8\u9001\u524d\u540e\u7aef\u843d\u5730\u5b9e\u8df5"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>\u6781\u5149\u63a8\u9001\u6ce8\u610f\u4e8b\u9879\n<ul class=\"wp-block-list\">\n<li>\u4e2a\u4eba\u5f00\u53d1\u8005\u6bcf\u5929\u514d\u8d39 10 \u6761\u5e7f\u64ad\u63a8\u9001\uff0c\u5355\u70b9\u8bbe\u5907\u63a8\u9001\u4e0d\u9650<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">flutter \u7aef\u914d\u7f6e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u914d\u7f6e <code>project\\android\\app\\build.gradle<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">defaultConfig{<br>    ...<br>     manifestPlaceholders = [<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  JPUSH_PKGNAME : applicationId,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  JPUSH_APPKEY : \"Appkey\", \/\/ NOTE: JPush \u4e0a\u6ce8\u518c\u7684\u5305\u540d\u5bf9\u5e94\u7684 Appkey.<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  JPUSH_CHANNEL : \"developer-default\", \/\/\u6682\u65f6\u586b\u5199\u9ed8\u8ba4\u503c\u5373\u53ef.<br> &nbsp; &nbsp; ]<br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u914d\u7f6e <code>project\\android\\app\\src\\main\\AndroidManifest.xml<\/code> \u6743\u9650\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;uses-permission android:name=\"android.permission.INTERNET\"\/&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u88c5\u4f9d\u8d56\u53ca\u6848\u4f8b<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">jpush_flutter: 3.0.0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6848\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import 'package:flutter\/material.dart';<br>import 'package:jpush_flutter\/jpush_flutter.dart';<br>\u200b<br>void main(){<br> &nbsp;runApp(MyApp());<br>}<br>\u200b<br>class MyApp extends StatelessWidget {<br> &nbsp;const MyApp({super.key});<br>\u200b<br> &nbsp;@override<br> &nbsp;Widget build(BuildContext context) {<br> &nbsp; &nbsp;return MaterialApp(<br> &nbsp; &nbsp; &nbsp;home: PageApp(),<br> &nbsp;  );<br>  }<br>}<br>\u200b<br>class PageApp extends StatefulWidget {<br> &nbsp;const PageApp({super.key});<br>\u200b<br> &nbsp;@override<br> &nbsp;State&lt;PageApp&gt; createState() =&gt; _PageAppState();<br>}<br>\u200b<br>class _PageAppState extends State&lt;PageApp&gt; {<br> &nbsp;@override<br> &nbsp;void initState(){<br> &nbsp; &nbsp;super.initState();<br> &nbsp; &nbsp;initJpush();<br>  }<br>\u200b<br> &nbsp;\/\/\u76d1\u542c\u6781\u5149\u63a8\u9001 (\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5)<br> &nbsp;\/\/https:\/\/github.com\/jpush\/jpush-flutter-plugin\/blob\/master\/documents\/APIs.md<br> &nbsp;initJpush() async {<br> &nbsp; &nbsp;JPush jpush = new JPush();<br> &nbsp; &nbsp;\/\/\u83b7\u53d6\u6ce8\u518c\u7684id<br> &nbsp; &nbsp;jpush.getRegistrationID().then((rid) {<br> &nbsp; &nbsp; &nbsp;print(\"\u83b7\u53d6\u6ce8\u518c\u7684id:$rid\");<br> &nbsp;  });<br> &nbsp; &nbsp;\/\/\u521d\u59cb\u5316<br> &nbsp; &nbsp;jpush.setup(<br> &nbsp; &nbsp; &nbsp;appKey: \"appkey\",<br> &nbsp; &nbsp; &nbsp;channel: \"theChannel\",<br> &nbsp; &nbsp; &nbsp;production: false,<br> &nbsp; &nbsp; &nbsp;debug: true, \/\/ \u8bbe\u7f6e\u662f\u5426\u6253\u5370 debug \u65e5\u5fd7<br> &nbsp;  );<br>\u200b<br> &nbsp; &nbsp;\/\/\u8bbe\u7f6e\u522b\u540d  \u5b9e\u73b0\u6307\u5b9a\u7528\u6237\u63a8\u9001<br> &nbsp; &nbsp;jpush.setAlias(\"jg123\").then((map) {<br> &nbsp; &nbsp; &nbsp;print(\"\u8bbe\u7f6e\u522b\u540d\u6210\u529f\");<br> &nbsp;  });<br>\u200b<br> &nbsp; &nbsp;try {<br> &nbsp; &nbsp; &nbsp;\/\/\u76d1\u542c\u6d88\u606f\u901a\u77e5<br> &nbsp; &nbsp; &nbsp;jpush.addEventHandler(<br> &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \u63a5\u6536\u901a\u77e5\u56de\u8c03\u65b9\u6cd5\u3002<br> &nbsp; &nbsp; &nbsp; &nbsp;onReceiveNotification: (Map&lt;String, dynamic&gt; message) async {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(\"flutter onReceiveNotification: $message\");<br> &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \u70b9\u51fb\u901a\u77e5\u56de\u8c03\u65b9\u6cd5\u3002<br> &nbsp; &nbsp; &nbsp; &nbsp;onOpenNotification: (Map&lt;String, dynamic&gt; message) async {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(\"flutter onOpenNotification: $message\");<br> &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \u63a5\u6536\u81ea\u5b9a\u4e49\u6d88\u606f\u56de\u8c03\u65b9\u6cd5\u3002<br> &nbsp; &nbsp; &nbsp; &nbsp;onReceiveMessage: (Map&lt;String, dynamic&gt; message) async {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(\"flutter onReceiveMessage: $message\");<br> &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp;  );<br> &nbsp;  } catch (e) {<br> &nbsp; &nbsp; &nbsp;print('\u6781\u5149sdk\u914d\u7f6e\u5f02\u5e38');<br> &nbsp;  }<br>  }<br> &nbsp;@override<br> &nbsp;Widget build(BuildContext context) {<br> &nbsp; &nbsp;return Scaffold(<br> &nbsp; &nbsp; &nbsp;appBar: AppBar(title:Text(\"flutter\u63a8\u9001\")),<br> &nbsp;  );<br>  }<br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u4e2d\u53ef\u4ee5\u901a\u8fc7 <code>jpush.setAlias<\/code> \u65b9\u5f0f\u4e3a\u8bbe\u5907\u8bbe\u7f6e\u522b\u540d,\u7528\u4e8e\u540e\u671f\u7684\u5355\u70b9\u63a8\u9001<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u672c\u5730\u7aef\u63a8\u9001<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">JPush jpush = new JPush();<br>var fireDate = DateTime.fromMillisecondsSinceEpoch(DateTime.now().millisecondsSinceEpoch + 3000);<br>var localNotification = LocalNotification(<br> &nbsp; &nbsp;id: 234,<br> &nbsp; &nbsp;title: '\u672c\u5730\u5e94\u7528\u63a8\u9001',<br> &nbsp; &nbsp;buildId: 1,<br> &nbsp; &nbsp;content: '\u5b9a\u65f6\u4efb\u52a1\u672c\u5730\u6d88\u606f\u63a8\u9001',<br> &nbsp; &nbsp;fireTime: fireDate,<br> &nbsp; &nbsp;subtitle: 'notification subtitle', \/\/ \u8be5\u53c2\u6570\u53ea\u6709\u5728 iOS \u6709\u6548<br> &nbsp; &nbsp;badge: 5, \/\/ \u8be5\u53c2\u6570\u53ea\u6709\u5728 iOS \u6709\u6548<br>);<br>jpush.sendLocalNotification(localNotification).then((res) {});<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Node\u7aef\u8c03\u7528\u6781\u5149\u63a8\u9001<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">nest\u7aef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>app.service.ts<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { Injectable } from '@nestjs\/common';<br>import { JPushAsync } from \"jpush-async\";<br>\u200b<br>@Injectable()<br>export class AppService {<br> &nbsp;async getHello() {<br> &nbsp; &nbsp;console.log(JPushAsync)<br> &nbsp; &nbsp;var client = JPushAsync.buildClient('appKey', 'masterSecret')<br> &nbsp; &nbsp;client.push().setPlatform('ios', 'android')<br> &nbsp;  .setAudience(JPushAsync.alias('jg123'))<br> &nbsp;  .setNotification(JPushAsync.android('\u9f9a\u7bad\u5411\u4f60\u53d1\u9001\u4e86\u4e00\u6761\u4fe1\u606f', '\u5b9a\u70b9\u6d88\u606f\u63a8\u9001\u6d4b\u8bd5', 1, {'key':'value'}))<br> &nbsp;  .send()<br> &nbsp;  .then(function(result) {<br> &nbsp; &nbsp; &nbsp; &nbsp;console.log(result)<br> &nbsp;  }).catch(function(err) {<br> &nbsp; &nbsp; &nbsp; &nbsp;console.log(err)<br> &nbsp;  })<br>\u200b<br> &nbsp; &nbsp;return {<br> &nbsp; &nbsp; &nbsp;code:101,<br> &nbsp; &nbsp; &nbsp;message:'hello world',<br> &nbsp; &nbsp; &nbsp;data:null<br> &nbsp;  };<br>  }<br>}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u4e2d <code>setAudience(JPushAsync.alias('jg123'))<\/code> \u4e2d <code>JPushAsync.alias('jg123')<\/code> \u4e3a\u8bbe\u5907\u7684\u522b\u540d\uff0c\u540c\u65f6\u652f\u6301\u591a\u8bbe\u5907\u63a8\u9001\u793a\u4f8b<code>JPushAsync.alias('xxx1','xxx2',...)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e7f\u64ad\u63a8\u9001<code>.setAudience(JPushAsync.ALL)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>app.controller.ts<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import { Controller, Get } from '@nestjs\/common';<br>import { AppService } from '.\/app.service';<br>\u200b<br>@Controller()<br>export class AppController {<br> &nbsp;constructor(private readonly appService: AppService) {}<br>\u200b<br> &nbsp;@Get()<br> &nbsp;getHello() {<br> &nbsp; &nbsp;return this.appService.getHello();<br>  }<br>}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/gjweb.top\/wp-content\/uploads\/2024\/05\/7cdd4f684ff8ae3e6503292e9af30f2a-00_00_00-00_00_30.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"216\" height=\"480\" data-original=\"https:\/\/gjweb.top\/wp-content\/uploads\/2024\/05\/7cdd4f684ff8ae3e6503292e9af30f2a-00_00_00-00_00_30.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-995\"\/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>flutter \u7aef\u914d\u7f6e \u914d\u7f6e project\\android\\app\\build.gradle default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63],"tags":[],"class_list":["post-994","post","type-post","status-publish","format-standard","hentry","category-flutter"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=994"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":996,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/994\/revisions\/996"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}