If you do not want to build your own push server, you can use the third-party API to implement the push function, this article mainly describes how ionic integrates Jpush.
The steps are as follows:
- Create Ionic app:Ionic_jpush.
- Apply Jpush Account: Create an app, upload a developer certificate, and record Jpush_api_appkey.
- Installing Jpush Plugin
First Way:cordova plugin add Jpush-phonegap-plugin--variable api_key=your_jpush_appkey
Second Way:cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git--variable api_key=your_jpush_ Appkey
Third Way:git clone Https://github.com/jpush/jpush-phonegap-plugin.gitcordova plugin add $JPUSH _plugin_dir -- Variable Api_key=your_jpush_appkey
Locate the path: ionic_jpush\plugins\cn.jpush.phonegap.jpushplugin\src\ios\pushconfig.plist, modify the Jpush_api_key, and fill in the following sections:
<key>APS_FOR_PRODUCTION</key><string>0</string>
- To add a push factory to the services:
. Factory (' Push ', function () {var Push; return {setbadge:function (badge) {if (push) {console.log (' Jpush:set badge ', badge); Plugins.jPushPlugin.setBadge (badge); }}, Setalias:function (alias) {if (push) {console.log (' Jpush:set alias ', alias); Plugins.jPushPlugin.setAlias (alias); }}, Check:function () {if (Window.jpush && push) {Plugins.jPushPlugin.receiveNotifica Tioninioscallback (Window.jpush); Window.jpush = null; }}, Init:function (Notificationcallback) {console.log (' Jpush:start init-----------------------'); Push = Window.plugins && window.plugins.jPushPlugin; if (push) {console.log (' jpush:init '); Plugins.jPushPlugin.init (); Plugins.jPushPlugin.setDebugMode (TRUE); Plugins.jPushPlugin.openNotificationInAndroidCallback = Notificationcallback; Plugins.jpuShplugin.receivenotificationinioscallback = Notificationcallback; } } }; })
- Initialize Jpush in App.js run and Add listener Events : Modify the alias "12345678" to be the name you want.
. Run (function ($ionicPlatform, Push) {$ionicPlatform. Ready (function () {//Hide the accessory bar by default (remove th is to show the accessory bar above the keyboard//for form inputs) if (Window.cordova && window.cordova.plu Gins && Window.cordova.plugins.Keyboard) {Cordova.plugins.Keyboard.hideKeyboardAccessoryBar (true); Cordova.plugins.Keyboard.disableScroll (TRUE); } if (window. StatusBar) {//Org.apache.cordova.statusbar required Statusbar.styledefault (); }//jpush callback method var notificationcallback = function (data) {Console.log (' Received data: ' + dat a); var notification = Angular.fromjson (data); Is the app in the running state var isActive = notification.notification; Here Add your code//ios if (ionic. Platform.isios ()) {Window.alert (notification); } else {//non-iOS (Android)}}; Initialize PUSH.INIT (notificationCallback); Set alias Push.setalias ("12345678"); Console.log (' Start to define AddEventListener '); var onopennotification= function (event) {Console.log ("jpushplugin:onopennotification is triggered"); }; var onbackgroundnotification = function (event) {Console.log ("jpushplugin:onbackgroundnotification is triggered" ); }; var onreceivenotification = function (event) {Console.log ("jpushplugin:onreceivenotification is triggered"); }; Console.log (' End to define AddEventListener '); Console.log (' Start to add AddEventListener '); Document.addeventlistener ("Jpush.opennotification", onopennotification, false); Document.addeventlistener ("Jpush.receivenotification", onreceivenotification, false); Document.addeventlistener ("Jpush.backgroundnotification", onbackgroundnotification, false); Console.log (' End to add AddEventListener '); });})
- To compile an iOS project:
Ionic Build IOS
- use Xcode to open a project: make a certificate configuration to ensure that the developer certificate you are using has APNs permissions.
- Push simulation is performed on the Jpush website.
Problems:
- A list of issues with iOS compilation failure: It's a good idea to ask an experienced iOS developer to help you troubleshoot.
- Unable to connect to Jpush server: Please check if Api_key is correct.
- Unable to receive push information: Please check that the push certificate is configured correctly on the Jpush website.
Resources:
- Jpush Plugin
- Ionic Custom Jpush
15th Chapter: Integrated Jpush