├── Android ├── JPushUtil.js └── JPushUtilPlugin.java ├── README.md └── iOS ├── JPushNotificationPlugin.h ├── JPushNotificationPlugin.m └── JPushUtil.js /Android/JPushUtil.js: -------------------------------------------------------------------------------- 1 | var JPushUtil = function() { }; 2 | 3 | JPushUtil.prototype.SetAlias = function(name, successCallback, failureCallback ) { 4 | return cordova.exec(successCallback, failureCallback, 'JPushUtilPlugin', 'setAlias', [name]); 5 | }; 6 | 7 | if(!window.plugins) { 8 | window.plugins = {}; 9 | } 10 | 11 | if (!window.plugins.JPushUtil) { 12 | window.plugins.JPushUtil = new JPushUtil(); 13 | } -------------------------------------------------------------------------------- /Android/JPushUtilPlugin.java: -------------------------------------------------------------------------------- 1 | package org.apache.cordova.plugin; 2 | 3 | import org.apache.cordova.api.CallbackContext; 4 | import org.apache.cordova.api.CordovaPlugin; 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | 8 | import android.content.Context; 9 | 10 | import cn.jpush.android.api.JPushInterface; 11 | 12 | public class JPushUtilPlugin extends CordovaPlugin { 13 | 14 | @Override 15 | public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { 16 | Context context = cordova.getActivity().getApplicationContext(); 17 | JPushInterface.setAliasAndTags(context, data.getString(0), null); 18 | return true; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jpush-phonegap-plugin 2 | ===================== 3 | 4 | A phonegap plugin for jpush, include iOS and Android source code and js. 5 | 6 | 7 | The first version, only add setTagAndAlias function for js, so you can call this function after user login in your html app. 8 | 9 | I will add notification to js call soon. -------------------------------------------------------------------------------- /iOS/JPushNotificationPlugin.h: -------------------------------------------------------------------------------- 1 | // 2 | // UrbanAirshipPlugin.h 3 | // urbanairship.richpush 4 | // 5 | // Created by urbanairship on 6/18/12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface JPushNotificationPlugin : CDVPlugin { 13 | 14 | } 15 | 16 | @end -------------------------------------------------------------------------------- /iOS/JPushNotificationPlugin.m: -------------------------------------------------------------------------------- 1 | 2 | #import "JPushNotificationPlugin.h" 3 | #import "APService.h" 4 | 5 | @implementation JPushNotificationPlugin 6 | 7 | - (void) setTagsAndAlias:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options 8 | { 9 | CDVPluginResult* pluginResult; 10 | NSString* callbackID = [arguments pop]; 11 | 12 | NSString *tags = [arguments objectAtIndex:0]; 13 | 14 | NSString *alias = [arguments objectAtIndex:1]; 15 | 16 | //NSLog(@"path %@, uti:%@", path, uti); 17 | 18 | NSArray *parts = [tags componentsSeparatedByString:@","]; 19 | [APService setTags:[NSSet setWithArray:parts] alias:alias]; 20 | 21 | pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @""]; 22 | [self writeJavascript: [pluginResult toSuccessCallbackString:callbackID]]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /iOS/JPushUtil.js: -------------------------------------------------------------------------------- 1 | /* 2 | THIS SOFTWARE IS PROVIDED BY ANDREW TRICE "AS IS" AND ANY EXPRESS OR 3 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 4 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 5 | EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 6 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 7 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 8 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 9 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 10 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 11 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | */ 13 | 14 | window.JPushUtil = { 15 | setTagsAndAlias: function (tags, alias, success, fail) { 16 | return cordova.exec(success, fail, "JPushNotification", "setTagsAndAlias", [tags, alias]); 17 | } 18 | }; 19 | --------------------------------------------------------------------------------