Giter Site home page Giter Site logo

konder / jpush-phonegap-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jpush/jpush-phonegap-plugin

0.0 2.0 0.0 2.09 MB

极光(JPush) 官方发布的PhoneGap plugin (Android & iOS). 修正了一些bug和实现一些功能

Home Page: http://docs.jpush.cn

CSS 30.03% JavaScript 64.68% Java 3.97% Objective-C 1.32%

jpush-phonegap-plugin's Introduction

#JPush Phonegap Plugin

修正官方源的bug和陆续实现一些功能。

##安装

cordova plugin add https://github.comg/konder/jpush-phonegap-plugin.git

##修改配置

###Android

修改config.xml,覆盖从极光控制台获取的AAPKEY和CHANNEL参数。

<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="YOUR_JPUSH_APPKEY"/>

修改"MainActivity.java",在onCreate的时候执行初始化,Handle在Resume和Pause时的逻辑。

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    //release时关闭
    JPushInterface.setDebugMode(true);
    JPushInterface.init(this);

    super.init();
    // Set by <content src="index.html" /> in config.xml
    super.loadUrl(Config.getStartUrl());
    //super.loadUrl("file:///android_asset/www/index.html");
}

@Override
protected void onResume() {
    super.onResume();
    JPushInterface.onResume(this);
}

@Override
protected void onPause() {
    super.onPause();
    JPushInterface.onPause(this);
}

###IOS

修改config.xml,启用JPushPlgin。

<feature name="JPushPlugin">
    <param name="ios-package" value="JPushPlugin" />
    <param name="onload" value="true" />
</feature>

修改代理类,执行初始化和处理didRegisterForRemoteNotificationsWithDeviceToken事件与didReceiveRemoteNotification的逻辑。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
 
    // Required
    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                    UIRemoteNotificationTypeSound |
                                                    UIRemoteNotificationTypeAlert)];
    // Required
    [APService setupWithOption:launchOptions];
     
    return YES;
}
 
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
     
    // Required
    [APService registerDeviceToken:deviceToken];
}
 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
     
    // Required
    [APService handleRemoteNotification:userInfo];
}

##使用

// 接收registrationID, 现在的设计有可能会因为早于JPush的cn.jpush.android.intent.REGISTRATION广播而无法获取。
// registrationID用来作为标示用户,可以取代setAlias,类似于APNS的token。
var tokenHandle = function(result){
    if (result && result['registrationID']) {
        alert(result['registrationID']);
    }
}

// 处理消息达到后的逻辑,扩展字段在event.extra。
var onNotification = function(event){
    alert(event.alert);
}

// 在onDeviceReady事件注册。
window.plugins.jPushPlugin.register(
    tokenHandle,
    onNotification
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.