15th Chapter: Integrated Jpush

Source: Internet
Author: User

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
    • Modify Configuration

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:

    1. A list of issues with iOS compilation failure: It's a good idea to ask an experienced iOS developer to help you troubleshoot.
    2. Unable to connect to Jpush server: Please check if Api_key is correct.
    3. Unable to receive push information: Please check that the push certificate is configured correctly on the Jpush website.

Resources:

    1. Jpush Plugin
    2. Ionic Custom Jpush

15th Chapter: Integrated Jpush

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.